Task-oriented vi cheat sheet

There are many vi references and cheat sheets, usually formatted as lists or groupings of keystrokes followed by what each one does.  I created this one for myself because I needed more of a cookbook, where I can scan through it looking for a match for what I need to do and then it shows me the needed the keystroke(s).

If you’re new to vi, remember :q!

Get out of insert mode – Esc

Move left – h
Move right – l
Move up – k
Move down – j

Switch to input mode just after the cursor position – a
Jump to end of line, then switch to input mode – A
Insert a blank line below the current line, then switch to input mode – o

Move to top of file – gg
Move to bottom of file – G
Move to beginning of line – 0 (zero)
Move to end of line – $

Delete character under cursor (delete) – x
Delete character to left of cursor (backspace) – X
Delete all characters to right of cursor, then switch to input mode – C
Join the line below to this line, inserting a space between – J

Delete current line – dd
Copy current line – yy
Paste – p

Search for string – /string
* search commands work like in less

Search and replace – :%s/<pattern>/<replacement>/<flags> where <flags> is blank or “c” for request confirmation

Undo last change – u
Undo all changes to current line – U

Turn on the line at the bottom which shows when you’re in Insert mode – :set showmode

Save changes – :w
Quit, checking for unsaved changes – :q
Get the heck out, leaving the file unchanged/undamaged – :q!

A much more comprehensive vi cheat sheet