Vim cheatsheet

$ vim # start vim

$ vim myfile.txt # edit named file - creates it if it doesn't exist

$ vim - # read and edit text from STDIN - use with pipe commands, eg:

$ ls -l | vim -

$ vimtutor # learn vim

$ vim -h # basic help

$ man vim # read the manual page for vim

Undo and redo

u - undo

Ctrl-r - redo

U - redo changes to last line

Saving and exiting

ZZ - Save and exit

ZQ - Discard changes and exit

:w - Save (write)

:w myfile.txt - write file with given filename - use to rename or if editing an unnamed buffer

Moving around

h - cursor left

l - cursor right

j - cursor down

k - cursor up

w - cursor to start of next word

b - cursor to start of previous word

Inserting

o - insert blank line below cursor and go into INSERT mode

O - insert blank line above cursor and go into INSERT mode

Deleting

dw - delete word under cursor

x - delete character under cursor

Copying and pasting

dd - cut line

2dd - cut 2 lines

V - select a group of lines then d to cut

p - paste lines below cursor

P - paste lines above cursor