logo

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 :
  • gg: Go to the beginning of the file
  • G: Go to the end of the file
  • 0: Go to the beginning of the line
  • ^: Go to the first non-blank character of the line
  • $: Go to the end of the line
  • w: Next word
  • b: Previous word
  • e: End of word
  • f<char>: Find character on the line
  • ;: Repeat previous f or F or t or T motion in the same direction
  • ,: Repeat previous f or F or t or T motion in the opposite direction
  • gd: Go to local definition

Insert mode

  • i: Insert before cursor
  • I: Insert at the beginning of the line
  • a: Append after cursor
  • A: Append at the end of the line
  • o: Open new line below
  • O: Open new line above

Editing actions

  • d: Delete (combine with motions, e.g., dw)
  • c: Change (e.g., cw to change word)
  • y: Yank (copy)
  • p: Paste after cursor
  • P: Paste before cursor
  • v: Enter visual mode
  • u: Undo
  • Ctrl+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 mode
  • V: Line-wise visual mode
  • o: Move to other end of selection

Case changing

Select the text then:

  • U: Uppercase
  • u: Lowercase
  • ~: Toggle case

Search & replace

  • /pattern: Search forward
  • ?pattern: Search backward
  • n / N: Next/previous match
  • :%s/old/new/g: Replace all in file

Saving & quitting

  • :w: Save
  • :q: Quit
  • :wq or :x: Save and quit
  • :qa!: Quit all without saving

References