My vim cheatsheet
Vim is a highly configurable text editor built to enable efficient text editing. It is based on a modal editing philosophy, where you switch between modes for inserting text, navigating, and issuing commands.
Modes
- Normal mode: Navigation and commands (default)
- Insert mode: Text input (
i,I,a,A,o,O) - Visual mode: Select text (
v,V,Ctrl+v) - Command-line mode: Commands starting with
:
Navigation
gg: Go to the beginning of the fileG: Go to the end of the file0: Go to the beginning of the line^: Go to the first non-blank character of the line$: Go to the end of the linew: Next wordb: Previous worde: End of wordf<char>: Find character on the line;: Repeat previousforFortorTmotion in the same direction,: Repeat previousforFortorTmotion in the opposite directiongd: Go to local definition
Insert mode
i: Insert before cursorI: Insert at the beginning of the linea: Append after cursorA: Append at the end of the lineo: Open new line belowO: Open new line above
Editing actions
d: Delete (combine with motions, e.g.,dw)c: Change (e.g.,cwto change word)y: Yank (copy)p: Paste after cursorP: Paste before cursorv: Enter visual modeu: UndoCtrl+r: Redo.: Repeat last command
Motions & text objects
i{object}: Inner object (inside)a{object}: Around object (including delimiters)- Common objects:
w(word),b(bracket),t(tag),q(quote) - Example:
ciw(change inner word),da"(delete around quotes)
Visual mode
v: Character-wise visual modeV: Line-wise visual modeo: Move to other end of selection
Case changing
Select the text then:
U: Uppercaseu: Lowercase~: Toggle case
Search & replace
/pattern: Search forward?pattern: Search backwardn/N: Next/previous match:%s/old/new/g: Replace all in file
Saving & quitting
:w: Save:q: Quit:wqor:x: Save and quit:qa!: Quit all without saving