Skip to main content

Vim/Neovim Cheat Sheet

· 3 min read

Modes

  • Normal mode: Esc - Default mode for navigation and commands
  • Insert mode: i - Type text before cursor; a - after cursor; I - start of line; A - end of line
  • Visual mode: v - character selection; V - line selection; Ctrl+v - block selection
  • Command mode: : - Execute commands
  • Basic movement: h (left), j (down), k (up), l (right)
  • Word movement: w (next word), b (previous word), e (end of word)
  • Line movement: 0 (start of line), ^ (first non-blank), $ (end of line)
  • Document movement: gg (file start), G (file end), {number}G (go to line number)
  • Screen movement: Ctrl+f (page down), Ctrl+b (page up), Ctrl+d (half page down), Ctrl+u (half page up)
  • Jump to matching bracket: %

Editing

  • Delete: x (character), dd (line), dw (word), d$ (to end of line)
  • Change: cw (change word), cc (change line), C (change to end of line)
  • Yank (copy): yy (line), yw (word), y$ (to end of line)
  • Paste: p (after cursor), P (before cursor)
  • Undo/Redo: u (undo), Ctrl+r (redo)
  • Repeat last command: .
  • Join lines: J

Search and Replace

  • Search: /pattern (forward), ?pattern (backward)
  • Next/Previous match: n (next), N (previous)
  • Replace: :s/old/new/ (first on line), :s/old/new/g (all on line)
  • Replace in file: :%s/old/new/g (all occurrences), :%s/old/new/gc (with confirmation)
  • Clear search highlighting: :noh

File Operations

  • Save: :w (write), :w filename (save as)
  • Quit: :q (quit), :q! (quit without saving), :wq or :x (save and quit)
  • Open file: :e filename
  • Reload file: :e!

Multiple Files/Windows

  • Split windows: :split or :sp (horizontal), :vsplit or :vsp (vertical)
  • Navigate windows: Ctrl+w h/j/k/l (move between splits)
  • Close window: :close or Ctrl+w c
  • Switch buffers: :bn (next), :bp (previous), :b {number/name} (specific buffer)
  • List buffers: :ls

Visual Mode Operations

After selecting text in visual mode:

  • d - delete selection
  • y - yank (copy) selection
  • c - change selection
  • > - indent right
  • < - indent left
  • = - auto-indent

Useful Combinations

  • ciw - change inner word (cursor anywhere in word)
  • ci" - change inside quotes
  • di{ - delete inside braces
  • yi( - yank inside parentheses
  • va} - visually select around braces (including braces)

Markers and Jumps

  • Set marker: m{a-z} (lowercase for file-specific, uppercase for global)
  • Jump to marker: '{a-z} (line), `{a-z} (exact position)
  • Jump back: Ctrl+o, Jump forward: Ctrl+i

Neovim-Specific

  • Built-in LSP: :LspInfo, :LspStart, :LspStop
  • Treesitter: :TSInstall {language}, :TSUpdate
  • Lua config: ~/.config/nvim/init.lua
  • Terminal: :terminal or :term, exit with Ctrl+\ Ctrl+n

Recording Macros

  • Start recording: q{a-z} (record to register a-z)
  • Stop recording: q
  • Play macro: @{a-z}, repeat with @@

Miscellaneous

  • Show line numbers: :set number or :set nu
  • Relative line numbers: :set relativenumber
  • Show invisible characters: :set list
  • Toggle paste mode: :set paste / :set nopaste
  • Spell check: :set spell, ]s (next error), [s (previous), z= (suggestions)
  • Fold: zc (close), zo (open), za (toggle)