Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Vim Tips

Vim Tips

Useful Tutorials

Key Mappings

  • Modes
    • i, I — insert/insert at beginning of line
    • a, A — append/append at end of line
    • o, O — open a new line after/before the current
    • v — visual selection
    • V — visual line selection
    • R — replace mode (replaces more than one char)
    • ⌃V — visual blocks mode
  • Undo/Redo and Copy & Paste
    • u, ⌃r — undo/redo
    • y — copy
    • yy=Y — copy whole line
    • p, P — paste after/before cursor
    • gp, gP — paste after/before cursor and put cursor one char after/before pasted text
    • yyp — duplicate line
  • Navigation
    • ⌃i = ⌃I = — go backwards (cursor position history)
      • Warning: if you remap , then ⌃i won't work anymore!
    • ⌃o = ⌃O — go forwards (cursor position history)
    • '', `` — go to last cursor position's first/actual char on line
    • ⌃u, ⌃d — 1/2 page up/down
    • ⌃b, ⌃f — page up/down
    • H, L — go to top/bottom of screen
    • gi — go to position where you last left insert mode
    • gv — reseselect last selection
    • '. — goto last edited line
    • g;, g, — goto previous/next edited position
    • gg, G — go to first line/last line (EOF)
    • (, ) — go to beginning/end of sentence
    • {, } — go to beginning/end of paragraph
    • 123gg = 123G — go to line 123
    • n% — go to the n-th % line
    • % — find corresponding bracket
    • f<c>, F<c> — forward/backward find first letter <c> (goto letter)
    • t<c>, T<c> — forward/backward find first letter <c> (goto before letter)
    • ⌃G — show current position in file
  • Text Navigation
    • w — goto after end of (next) word
    • W — goto after end of (next) word (and after fullstops, etc.)
    • e — goto end of (next) word
    • b — goto beginning of previous word
    • B — goto beginning of previous word (and before fullstops, etc.)
    • 0, $ — goto absolute start/end of line
    • ^, g_ — goto start/end of line
  • Marks
    • m<c> — set mark named [a-z]
    • '<c> — goto line of mark <c>
    • `<c> — goto exact position of mark <c>
  • Text Selection
    • vaa, Vaa — select everything (line mode)
    • vib — select text inside the parenthesis block (of the cursor)
    • vi", vi' — select text inside double/single quotes
    • vi{ — select text inside paragraph
  • Text Manipulation
    • {visual}p — replace selected word with clipboard (register "")
    • ⌃A, ⌃X — increment/decrement a number
    • ~ — change case of current letter
    • rX — replace char with X
    • ce — change from current position to word end
    • C, c$ — change until end of line
    • cc — change current line
    • ciw, caw — change inner/a word
    • cib, cab — change inner/a block
    • ci{, ca{ — change inner/a paragraph
  • Formating
    • ⌃d, ⌃t — indent/deindent line in Insert mode
    • gqq — reformat current line
    • gqap — reformat current paragraph
    • J — join lines
    • = — auto indent
    • <num>o⎋⎋, <num>O⎋⎋ — insert <num> lines below/above
  • Auto Completion
    • ⌃N — dictionary completion
    • ⌃P — dictionary completion
    • ⌃X⌃O — omni completion (opens preview window for details)
    • ⌃W⌃Z — close preview window
  • Search
    • /<query>, ?<query> — forward/backward search for <query>
    • /, ? — search again for the last searched query
    • n, N — next/previous search result
    • *, # — search for word under cursor forward/backward
    • q/ — show history list of recent searches
  • Replacing Text
    • :s/<old>/<new>/g — replace <old> with <new>
      • flag g — global for current line (replace all matches)
      • flag c — confirm substitution matches
        • y, n, a, q — yes/no/all remaining/quit
      • flag i — ignore case
    • :#,#s/<old>/<new>/g — replace from line # to line #
    • :%s/<old>/<new>/g — replace in whole file
    • %s//<new>/ — replace last searched query with <new>
      • * and %s//<new>/ — search for word under cursor and replace it with <new>
  • Split Window/Tab Navigation
    • ⌃W h, ⌃W l — goto left/right split
    • ⌃W j, ⌃W k — goto below/above split
    • ⌃W ⌃W — jump between splits
    • ⌃W s, ⌃W v — split horizontally/vertically
    • ⌃W c — close current window
    • ⌃W o — close all windows except current
    • ⌃W |, ⌃W _ — maximise (v)split size
  • Folding
    • zf{motion}, {Visual}zf — fold {motion} lines/fold selection
    • zd, zD — delete a fold (recursivly)
    • zE — eliminate all folds in file
    • zo, zc, zO, zC — open/close fold (recursivly)
    • za, zA — open and close (toggle) a fold (recursivly)
    • zR, zM — open/close all folds
    • zj, zk — goto start/end of the next/previous fold
  • Macros
    1. q<c> — start recording
    2. q — stop recording
    3. @<c> — play recorded macro
    • @@ — replay previously played macro
  • Command Line
    • q: — show history list of recently executed commands
    • ⌃D — autocomplete filename while doing :e ~/D or simply : to see possible commands
  • Commands
    • :x, ZZ — save and exit
    • ⌃wq — exit if nothing to save
    • :new — new window
    • :sp — split window
    • :vsp — vertical split window
    • :e <file> — edit file
    • :r <file> — read file
    • :! — execute shell command
  • Misc
    • Saving a text selection to a file
      1. v
      2. select some text
      3. :w test.txt — saves the selected text to file 'test.txt'
    • ]p — pastes the contents of a buffer (automatically adjusting the indent)
    • zb, zz, zt — scroll screen so that current line is at the bottom/middle/top

Vimdiff

  • [c, ]c — goto next/previous difference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment