Vim #
A modal editor: keys do different things depending on the mode. Press Esc to return to Normal mode, where most commands live. Commands compose, so a count and a motion combine: 3dw deletes three words.
Modes #
| Key | Mode |
Esc | Back to Normal mode |
i a | Insert before / after the cursor |
I A | Insert at line start / end |
o O | Open a new line below / above |
v V | Visual (character / line) select |
Ctrl-v | Visual block select |
: | Command-line mode |
Motions #
| Key | Moves to |
h j k l | Left, down, up, right |
w b e | Next word, back a word, end of word |
0 ^ $ | Line start, first non-blank, line end |
gg G | First line, last line |
{ } | Previous / next paragraph |
Ctrl-d Ctrl-u | Half page down / up |
% | Matching bracket |
f x t x | Jump to / before next x on the line |
Editing #
| Key | Action |
x r | Delete char / replace one char |
dd yy p | Delete line, yank line, paste |
dw cw | Delete / change a word |
d$ c$ | Delete / change to end of line |
ciw ci" | Change inner word / inside quotes |
>> << | Indent / outdent the line |
u Ctrl-r | Undo / redo |
. | Repeat the last change |
J | Join the next line up |
Search & replace #
/pattern search forward ?pattern search backward
n N next / previous match
* # search word under the cursor
:%s/old/new/g replace all in the file
:%s/old/new/gc ... with confirmation per match
:s/old/new/g replace all on the current line
:noh clear search highlight
Buffers, windows, tabs #
:e file open a file :w write :q quit :wq write+quit
:bn :bp next / prev buffer :ls list buffers
:sp :vsp split horizontal / vertical
Ctrl-w h/j/k/l move between splits Ctrl-w q close split
:tabnew new tab gt gT next / prev tab
Survival #
| Key | Action |
:q! | Quit without saving |
ZZ | Save and quit |
:w !sudo tee % | Save a file you opened without sudo |
q: | Open the command history window |
:help x | Help for command x |
gg=G | Re-indent the whole file |
Ctrl-o Ctrl-i | Jump to older / newer cursor position |