Vim is everywhere on Linux servers, and it is modal - keys do different things depending on the mode. Here is the cheat sheet, including the famous one. Try every command in the free online Linux terminal, and learn it properly in the Vim lesson.
How to exit Vim
:q- quit (if nothing changed):q!- quit and discard changes:wqor:x- save and quitZZ- save and quit (from normal mode)
Press Esc first if a command does not seem to work - you are probably in the wrong mode.
Modes
- Normal - where you move and run commands (press Esc to get here)
- Insert - typing text (
i,a,o) - Command-line - the
:commands above
Moving
h j k l- left, down, up, rightw/b- next / previous word0/$- start / end of linegg/G- top / bottom of file:42- jump to line 42
Editing
x- delete a character;dd- delete a line;dw- delete a wordyy- copy a line;p- pasteu- undo;Ctrl+r- redor- replace one character;cw- change a word
Search and replace
/word- search forwards;n/N- next / previous match:%s/old/new/g- replace every occurrence in the file:%s/old/new/gc- same, but confirm each one
Build the muscle memory
Vim only sticks with practice. Open the online Linux terminal and edit a real file, or work through the free Learn Linux course.