So you want to be a hipster, I mean be efficient and learn vim keybindings? As with everything, the beginning will be hard, but all it takes is practice and muscle memory.

Getting help

You can’t learn this by simply reading. Make sure to practice often and use the available manuals and tutorials, they are actually quite good.

Use vimtutor as an excellent beginner tutorial.

vimtutor

Read up on a specific topic.

# Seriously, you can get help about everything
:help word
:help WORD
:help d
:help $

Normal mode

DescriptionKey
Move lefth
Move rightl
Move upk
Move downj
Move word forwardw
Move word backwardb
Move word ende
Move WORD forwardW
Move WORD backwardB
Move to end of WORDE
Move to end of line$
Move to beginning of line0
Move to first non empty character of line^
Move to specific character on linef + character
f. jump to the next dot on the line
Move to previous character on lineF + character
F. jumps to the previous dot on the line
Move sentence up(
Move sentence down)
Move paragraph up{
Move paragraph down}
Move half page upctrl + u
Move half page downctrl + d
Move full page upctrl + u
Move full page downctrl + b
Move to start of pagegg
Move to end of pageG
Move to next curly braces, square brackets or parenthesis%
Move to the top of the screenH
Move to the middle of the screenM
Move to the bottom of the screenL

Info

Keys can be prefixed with an number. For example 20 k moves you up 20 times.

Info

WORD is not the same as word. WORD is always delimited by whitespace.

  • ansible.builtin.import_role: is a single WORD.

word is delimited by non-keyword characters. All of these are separate words:

  • ansible
  • .
  • builtin
  • .
  • import_role
  • :

Manipulating text

DescriptionKey
Copy full lineyy
Paste full linep
Undou
Undo all changes on a lineU
Redoctrl + r
Dele full linedd
Delete a wordd + i + w
Delete a WORDd + i + W
Delete paragraphd + i + p
Delete sentenced + i + s
Delete up to specific characterd + t + character
dt{ deletes up to next {
Change wordc + i + w
Change whole lineC
Repeat previous operation.
Search forward for character/ + character
/atlantis moves to first iteration of the word atlantis from the cursor
Iterate forwardn
Iterate backwardN
Search forward for word under cursor*
Search backword for word under cursor#
Create markpointm + character
ma creates markpoint named a
Move to markpoint` + char
`a moves to markpoint a
Move to previous location` + `
Move to last edited location` + .
Join next 3 lines together3 + J
Make word uppercaseg + U + w
Make world lowercaseg + u + w
Make line lowercaseg + u + u
Make line uppercaseg + U + U
Increment a numberctrl + a
Decrement a numberctrl + x
Replace character on current positionr + character
r + x replaces the current character with x
Replace test with develop in whole file:s/test/develop/g
Replace ‘initial’ with ‘replacement’ in the 10 lines below the current line:.,.+10s/initial/replacement/g
Replace ‘foo’ with ‘bar’ between line 50 and 75:50,75s/foo/bar/g
Move to previous location in jump listctrl + o
Move to next location in jump listctrl + i
Show jump list:jumplist
:h jump-motions for more details

Folding

DescriptionKey
Fold all code blocksz + M
Unfold all code blocksz + R
Fold individual code blockz + c
Unfold individual code blockz + o

Advanced

DescriptionKey
Start recordingq + character
q + a stored recording as a
Stop recordingq
Apply recording@ + character
@ + a applies recording a
15 + @ + a applies macro a 15 times
Enable relative line numbering:set relativenumber

Switching modes

DescriptionKey
Insert mode before cursori
Insert mode after cursora
Insert mode at beginning of lineI
Insert mode at end of lineA
Insert mode after current lineo
Insert mode before current lineO
Change word and switch to insert modec + w
Change full line and sitch to insert modec + c

Insert mode

Visual mode

Command mode

DescriptionKey
Sort and keep unique entries:sort u
Sort:sort
Sort reversed order:sort!
Load external file to cursor position:read filename
:read /tmp/x.txt reads the file and places the contents at cursor position
Load output from STDOUT to cursor position:read !command
:read !ls -ltr parses the output of ls -ltr to the current cursor position
Substitute on line:s/old/new/g
Subtitute on file:%s/old/new/g
Substitute between line numbers:#,#s/old/new/g
:10,20s/hi/hello/g substitutes hi to hello between line 10 and 20
Run commands:!command
:!ls -ltr runs the ls -ltr command
Write to specific file:w FILENAME
:w /tmp/test.txt

Registers

Vim uses a set of registers. You can use these register using the " key.

Info

If you do not have a system (+) register, make sure to install vim-gtk3.

apt install vim-gtk3
DescriptionKey
List all register:reg
Use a specific register” + register + operation
"+y yanks the current line to the + register, which is the clipboard
"3p pastes the text stored in register 3

References

The road to mastering vim

I’ve attempted to start using vim bindings for a while now. The initial experience is extremely bad because I am 30 times slower with vim bindings than without. Much of that can be blamed on the fact that I just wanted to switch over completely in a big bang approach.

This time, I’ll try a different approach. Learn and master a small set of vim motions until I am proficient with them before attempting to learn more.

The first set of motions

  • Focus on moving the cursor via jkhl.
  • ^ and $ to move to beginning and end of line.
  • Use g and G modifiers (dG,vgg).
  • Move back and forth between words and WORDS using b,B,w,W.
  • a and A to start inserting text.
  • Insert text at current position or beginning of line via i and I.
  • Using G to jump to specific locations (16G to move to line 16).
  • Utilize the c modifier to replace content. (ci" replaces everything between quotes).

The second set of motions

  • f,F
  • t,T
  • a(
  • a{
  • Navigate to previous location of jump list with Ctrl + i.
  • Navigate to next location of jump list with Ctrl + o.

Neovim

Neovim is an editor based on vim.

LazyVim

Neovim is extremely customizable. So much that it might look very daunting in the beginning. Luckily there are tools like LazyVim that can help you to get a decent set up out of the box.