Easy Vim Guide

November 24, 2024

linuxvim

Vim for Beginners

cirno from assets

Megumin approves

Introduction

So, you got yourself a shiny new (or old) ThinkPad to put Linux on to flex on r/unixporn and r/thinkpad. You throw out any remaining masculinity, don your cutest thigh-highs and boot into an Arch ISO. Then reality hits you in the face — you don’t have internet to save your ass by sudo pacman -S nano-ing your way out of editing the locale.conf. Or maybe you fell for the HHKB hype — the allure of a decade-old Japanese keyboard with worn rubber domes, topre goodness you overpaid for on eBay, and no dedicated arrow keys.

Alternatively, like me, you might attempt to ditch your overpriced, overengineered mouse for no logical reason and write code the GNU way. Regardless of the reason, you’re here to get your hands dirty and learn Vim.

Contrary to what most Vim-tards claim, Vim (or Vi IMproved) didn’t adopt its strange motion keybindings just so the r/linux neckbeards (jk, i love them) could keep their hands on the home row for “efficiency.” Instead, these bindings originated from the ADM-3A keyboard layout, where the HJKL keys were literally the arrow keys. Here’s what that keyboard looked like (yes, there is a “rub” key…):

ADM-3A Keyboard Layout

ADM-3A Keyboard Layout

But hey, whatever helps r/linux and the RTFM folks sleep at night.

Let’s dive in.

Setting up Vim in IDE

There exists a Vim plugin for any and every IDE. I will be using Cursor because it’s literally an autocomplete for writing shitty scripts I write for my system.

vim-extension

vim extension on your IDE

Just download the right extension on your IDE.

Type in set number to have numbered lines, although this might be the default behavior of the IDE. The linux bourgeois (kinda ironic. idk why I said that) use relative numbering. Use the command set relativenumber to have relative numbering. This helps you do some stuff that we talk about later.

Basic Features

Vim Motions

Vim has three primary modes:

The NORMAL mode is where you type in your fancy Vim commands. The INSERT mode lets you insert text into your files. The VISUAL mode lets you visually select and manipulate text.

In NORMAL mode, use h, j, k, and l to move the cursor:

Word and Line Navigation

For lines:

Advanced Navigation

To scroll:

You might want to add funny ASCII art to the beginning of your config. To do this the Vim way, we use gg. To move to the end of the page, we use G (shift + G).

Editing Text

vim editing

editing text in vim

Take note of the cursor position

Copy, Paste, and Undo

Deleting Text

You will probably need the last one to quickly delete your yaoi fanfic at work.

Changing Text

Use . (dot) to repeat the last change command.

Search and Replace

Intermediate Motions

Function Folds

Fold (minimize) a function in our editor, we use z,c (close). To unfold, use z,o (open).

To operate on all functions in the current file, we use z,M and z,R.

We can select some lines in VISUAL mode and shift them left or right using the < or > keys.

To add the same prefix to multiple lines, we select the lines using VISUAL BLOCK mode and then press the I key to add the word to multiple lines.

Macros

Folding

Case Conversion

Bookmarks

Set a bookmark on a line with ma (bookmark a). Jump to it with `a. Toggle between the last two locations with “.

Running External Commands

Running external commands can be done by using something like this:

:read !whoami

You could also send a block of code, e.g. JSON, to a command and parse it.

{
  "firstname": "quiet",
  "lastname": "owo"
}

So now running !jq .firstname replaces the block of text with "quiet".

Conclusion

Congrats, now you can ramble on about how you code in Vim and act all holier-than-thou with your friends and solidify your virginity with :wq!.

I am still contemplating if this is actually worth the effort learning properly considering I have school and actual work. Lowkey miss unemployment.

Cheers!
quiet🌸