VIM Cheatsheet

Motion, keyboard commands and shortcuts for VI Improved

Graphic
Graphic

Legend

CommandKeyboard Character
command
control
alt
delete
option
shift
caps lock
tab
arrow up
arrow down
arrow left
arrow right
escape or
return/enter or
home
end
page up
page down

Motion - Normal Mode

  • j - Down
  • k - Up
  • h - Left
  • l - Right
  • 0, ⇧6 - Line beginning
  • $ - Line ending
  • e, w - Forward (Small word)
  • ⇧e, ⇧w - Forward (big word forward (whitespace only))
  • b - Backwards (small word)
  • ⇧b - Backwards (big word)
  • f<char> - Jump to first occurrence of <char>
  • ; - Repeat previous jump
  • ⇧f<char> - Jump to previous first occurrence of <char>
  • t<char> - Jump to position before first occurrence of <char>
  • ⇧t<char> - Jump to position before first previous occurrence of <char> in the direction youre searching
  • <n> <motion> - Prefix motion command with a number n to have it jump that n away. e.g. 4li jumps to the 4th ‘i’ forward.
  • ⌃f - Forward (page)
  • ⌃b - Backward (page)
  • ⌃u - Upward (half page)
  • ⌃d - Downward (half page)
  • ⇧h - Head (of current page)
  • ⇧m - Middle (of current page)
  • ⇧l - Lowest (of current page)
  • gg - Go to top of file
  • ⇧gg - Go to bottom of file
  • <n>⇧g - Go to line n
  • ][ - Jump to next matching brace
  • [] - Jump to previous matching brace
  • % - Jump between matching braces
  • za - Toggle code fold
  • zo - Open code fold
  • zc - Close code fold
  • zr - Open one layer of code folds
  • z⇧r - Open all code folks

Insert Mode

These commands are entered while in Normal or visual mode.

  • i - Insert at cursor
  • ⇧i - Insert at line beginning
  • a - Append after cursor
  • ea - Append after word at cursor
  • ⇧a - Append at end of line
  • o - Insert line below cursor
  • ⇧o - Insert line above cursor
  • x - Delete character under cursor
  • ⇧x - Delete character before cursor
  • dd - Delete line at cursor position
  • d <motion> - Delete amount by motion command e.g. dw delete small word
  • c <motion> - Change by motion e.g. cw overwrite small word
  • r - Replace character at cursor
  • ⇧r - Replace overwriting text
  • ^v u <codepoint> - Insert unicode character at codepoint
  • - Exit insert mode

Changes

  • ⇧j - Join line with line below
  • c(f|t)<char> - Change characters (inclusive with f or exclusive with t) to char

Yank/Put or Copy/Paste

  • y - Yank cursor or selection into default buffer
  • ”<r>y - Yank cursor or selection into register a (a: can be any letter, e.g. a, b, c)
  • yw - Yank word into buffer
  • yy - Yank line into buffer
  • <n>yy- Yank n lines into buffer
  • y <motion> - Yank into buffer by motion
  • x - Yank character at cursor
  • p - Put default buffer after cursor
  • ⇧p - Put buffer before cursor
  • ”<r>p - Put value from register a before cursor (a: can be any letter, e.g. a, b, c)

Visual / Visual Block Mode

Visual mode is used for marking text.

  • v - Visual mode
  • V - Visual line-based mode
  • ⌃v - Visual block mode
  • gv - Re-select previous Visual block buffer
  • o - Jump to other end of block
  • ⇧o - Jump to other corner of block
  • vaw - Visual select a word (includes whitespace)
  • viw - Vissual select inner word (no whitespace)
  • vap - Visual select a paragraph
  • vip - Visual select inner paragraph
  • va[ - Visual select [] block and contents
  • vi[ - Visual select [] contents only
  • va{ - Visual select block and contents
  • vi{ - Visual select contents only
  • va( - Visual select parens block and contents
  • vi( - Visual select parens contents only
  • va< - Visual select <> block and contents
  • vi< - Visual select <> contents only
  • va” - Visual select all double quote and contents
  • vi” - Visual select inner quoted contents
  • vit - Visual select inner XML/HTML tag contents
  • vat - Visual select all XML/HTML tag contents
  • v<motion> - Visually mark text by motion command
  • - Exit visual mode

The following commands can be used while text is marked.

  • c - Delete and begin inserting (To replace currently marked text)
  • d - Delete
  • y - Yank
  • > - Indent right
  • < - Indent left

Commands

  • . - Repeat previous command
  • u - Undo previous command
  • ⇧u - Undo all changes to current line
  • ⌃r - Redo
  • :q - Quit
  • :q! - Quit (without saving changes)

Files

  • :e <path> - OpEn file into buffer
  • :w - Write buffer to file
  • :ls - List open buffers
  • :(b|buf|buffer) <n> - Switch to buff n
  • :(bd|bdelete) <n> - Delete buffer n (close file)
  • :bp - Switch to previous buffer
  • :bn - Switch to next buffer

Windows

  • ⌃wo - make current window the Only window
  • :(sp|spl|split) <path> - SPlit window horizontally, optionally loading file at path
  • :vsp <path> - Vertically SPlit window, optionally loading file at path
  • ⌃ws - Window split (horizontally)
  • ⌃wv - Window split (vertically)
  • ⌃wx - Windows eXchange, swap their position
  • ⌃wk - Move window up
  • ⌃wj - Move window down
  • ⌃wh - Move window left
  • ⌃wl - Move window right
  • ⌃wp - Move window previous
  • ⌃wc - Window close
  • ⌃w= - Balance windows
  • ⌃w+ - Grow horizontal window split by 1
  • ⌃w- - Shrink horizontal window split by 1
  • ⌃w> - Grow vertical window split by 1
  • ⌃w< - Shrink vertical window split by 1
  • :(resize|res) (+|-)<n> - Horizontal resize to n or increase/decrease by n
  • :vertical resize (+|-)<n> - Vertical resize to n or increase/decrease by n

Tabs

  • gt - GoTo next tab
  • g⇧t - Goto previous tab
  • <n>gt - Goto tab n
  • :tabedit <file> - Edit specified file in a new tab
  • :tabfind <file> - Open a new tab with filename given
  • :tabclose - Close tab
  • :tabclose <n> - Close tab n
  • :tabonly - Close all other tabs

coc.nvim

  • ,dj Open implementation at cursor (coc-implementation)
  • ,dd Open symbol definition at cursor (coc-definition)
  • ,dr Open panel of symbol references at cursor (coc-references)

Denite

  • ; - fuzzy-search buffers for a string
  • ,t - fuzzy-search current directory for string
  • ,j - fuzzy-search current directory for string at cursor

Help

  • :h - Open Help
  • ⌃] - Activate link at cursor
  • ⌃T - Back

Search / Replace

  • /<pattern> - Search forward for pattern
  • ?<pattern> - Search backward for pattern
  • n - Jump to next match in searching direction
  • ⇧n - Jump to next match in opposite direction
  • :<range>s/<foo>/<bar>/[g,i,I,c] - Replace old with new. range is either empty, % for whole file, or a line number. g flag replaces all occurrances on the line. i ignores case. I doesn’t ignore case. c asks for confirmation.
  • * <n|⇧n> - Search forward for word at cursor, n jumps to Next result, N jumps to previous
  • # <n|⇧n> - Search backward for word at cursor, n jumps to Next result, N jumps to previous

Find Files

For finding patterns in files. Use :vimgrep if unsure if the grep command-line utility is available, but :grep is generally faster. All searches fill a buffer that is accessible by the :cw command.

  • :vimgrep /<pattern>/[g][j] <path/*/> - Search for regex pattern located in path. The g option specifies that all matches for a search will be returned instead of just one per line, and the j option specifies that Vim will not jump to the first match automatically.
  • :grep <pattern> <path> - Search for regex pattern located in path.