vi Cheat Sheet

vi or vim Cheat Sheet

Basic Cursor Movement:
h   Move left
j   Move down
  Move up
  Move right
H    Move to top of screen
   Move to bottom of screen
   Move to the beginning of the line
$    Move to the end of the line

Search for strings:
/string      Search forward for string
?string      Search back for string
        Search for next instance of string
         Search for previous instance of string

  Insert before cursor
a   Append after cursor
  Replace one character

   Delete character to the right of cursor
   Delete character to the left of cursor
D    Delete to the end of the line
dd    Delete current line
:d    Delete current line

:wq   Save and Exit.
ZZ   Save and Exit Shortcut.
:q   Exit only, there’s no changes to the file.
:q!  Exit and ignore any changes.