This is a cheatsheet of the commands I most frequently use for Vim. For a beginner’s guide to Vim, refer to my post Starting Vim.
Necessary commands
- Going into the Insert mode:
istarting before the current cursor positionastarting after the current cursor positionoadds a new blank line after the current cursor position and goes into the insert mode
uundo last editctrl+rredo- Exiting vim:
:wwrite file:qquit, assuming you haven’t made any changes in the file:xor:wqwrite file, then quit
Finding things
f+patterngoes to the next instance ofpatternin that line/patternsearches forward from the current cursor position for the text matchingpattern. Press/, type the search term (pattern), and pressEnter.- To search for the word “example”: first, ensure you are in Normal mode by pressing
esc. Then type/exampleand pressEnter. - To navigate search results,
nmoves to the next occurrence of the search pattern. Nmoves to the previous occurrence of the search pattern.
- To search for the word “example”: first, ensure you are in Normal mode by pressing
?patternsearches backward from the current cursor position for the text matchingpattern. Press?, type the search term (pattern), and pressEnter.- To search backward for the word “example”, you would type
?examplein Normal mode and pressEnter.
- To search backward for the word “example”, you would type
Moving around the line
^or0goes to the beginning of the line$goes to the end of the linegggoes to the beginning of the line
Moving around the file
:0goes to line zero:135goes to line 135:+5goes 5 lines forward:-5goes 5 lines backwardGgoes to the last line of the file
Text editing
dddelete current lined$orDdeletes from current cursor position to the end of the line