VIM: My Personal Cheat Sheet

Movement

Key Meaning
h, j, k, l ⬇️,⬅️, ➡️, ⬆️. Also normal arrow keys work fine. Some people like to disable them to “avoid bad habits” but I think it’s OK, because a lot of software will still force you to use it.
w, b, e, ne Word movement is one of the most essential to grasp for faster navigation in the beginning of your vim career:- Start of next word.- Start of previous word.- End of next word.- End of previous word.
^b, ^f, ^u, ^d Page movement:- One screen backwards or forwards.- 1/2 screen up or down.

Mouse Support

Allows you to scroll around and position cursor on screen.

On Linux, set :set mouse=a which should work out of the box, even in WSL via Windows Terminal.

On Windows version of vim this doesn’t work at all and I haven’t found solution yet.

Editing

Key Meaning
o Apend (open) a new line below the current line.
O Same as above, but above the current line.
d0 Delete from cursor to beginning of line.
d$ Delete from cursor to end of line.
ggdG Delete all text. gg goes to start of file. dG - delete to end (G).

Selection

Also called Visual Mode.

Key Meaning
v Go to visual mode to select characters.
V Go to visual mode to select lines.
i} Expand selection when in visual mode. Finds first enclosing {} and selects inside it.
a} Expand selection when in visual mode. Finds first enclosing {} and selects around it.
ggVG Select all text in the current document. gg goes to start of file. V enters visual mode. G goes to end of file.

Copy/Paste

Key Meaning
y Copy (yank) current selection.
d Cut (delete) current selection.
"*y Copy to system register (clipboard).
"*p Paste from system register (clipboard).

Basic search - type / then keep typing search phrase and when happy press enter. Move between occurrences with n (next) and N (previous, reverse of Next).

To turn on case-insensitive search - :set ic. ic stands for ignore case. To switch off - :set noic.

Useful Customisations

Enable Folding

set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=1

Use zo to open fold, and zc to close fold.

Select Colour Scheme

Start typing :colorscheme<space><tab> which displays list of colour schemes you can try immediately:

When happy, put it in .vimrc like :colorscheme <name>.

Plugins

There are many options, but I prefer vim-plug for managing plugins. It’s small and easy to use.

Have a question⁉ Contact me.


vim

429 Words

2021-12-12