Movement
h— Move cursor leftj— Move cursor downk— Move cursor upl— Move cursor rightH— Move to top of screenM— Move to middle of screenL— Move to bottom of screenw— Jump forwards to the start of a wordW— Jump forwards to the start of a word (words can contain punctuation)e— Jump forwards to the end of a wordE— Jump forwards to the end of a word (words can contain punctuation)b— Jump backwards to the start of a wordB— Jump backwards to the start of a word (words can contain punctuation)ge— Jump backwards to the end of a wordgE— Jump backwards to the end of a word (words can contain punctuation)%— Move cursor to matching character ((),{},[])0— Jump to the start of the line^— Jump to the first non-blank character of the line$— Jump to the end of the lineg_— Jump to the last non-blank character of the linegg— Go to the first line of the documentG— Go to the last line of the documentgd— Move to local declarationgD— Move to global declarationfx— Jump to next occurrence of character xtx— Jump to before next occurrence of character xFx— Jump to the previous occurrence of character xTx— Jump to after previous occurrence of character xzz— Center cursor on screenCtrl+d— Move cursor and screen down 1/2 pageCtrl+u— Move cursor and screen up 1/2 page
Insert Mode
i— Insert before the cursorI— Insert at the beginning of the linea— Insert (append) after the cursorA— Insert (append) at the end of the lineo— Open a new line below the current lineO— Open a new line above the current lineea— Insert (append) at the end of the wordCtrl+t— Indent (move right) line one shiftwidthCtrl+d— De-indent (move left) line one shiftwidthCtrl+n— Auto-complete next matchCtrl+p— Auto-complete previous match
Edit
r— Replace a single characterR— Replace more than one character, until ESC is pressedJ— Join line below to the current one with one space in betweengJ— Join line below to the current one without space in betweengwip— Reflow paragraphg~— Switch case up to motiongu— Change to lowercase up to motiongU— Change to uppercase up to motioncc— Change (replace) entire linec$orC— Change (replace) to the end of the lineciw— Change (replace) entire wordcworce— Change (replace) to the end of the words— Delete character and substitute text (same ascl)S— Delete line and substitute text (same ascc)xp— Transpose two letters (delete and paste)u— UndoU— Restore (undo) last changed lineCtrl+r— Redo.— Repeat last command
Indent
>>— Indent (move right) line one shiftwidth<<— De-indent (move left) line one shiftwidth>%— Indent a block with()or{}(cursor on brace)<%— De-indent a block with()or{}(cursor on brace)>ib— Indent inner block with()>at— Indent a block with<>tags3==— Re-indent 3 lines=%— Re-indent a block with()or{}(cursor on brace)=iB— Re-indent inner block with{}gg=G— Re-indent entire buffer]p— Paste and adjust indent to current line
Visual Mode
v— Start visual mode, mark lines, then do a command (like yank)V— Start linewise visual modeo— Move to other end of marked areaCtrl+v— Start visual block modeO— Move to other corner of blockaw— Mark a wordab— A block with()aB— A block with{}at— A block with<>tagsib— Inner block with()iB— Inner block with{}it— Inner block with<>tags
Visual Commands
>— Shift text right<— Shift text lefty— Yank (copy) marked textd— Delete marked text~— Switch caseu— Change marked text to lowercaseU— Change marked text to uppercase
Cut and Paste
yy— Yank (copy) a line2yy— Yank (copy) 2 linesyw— Yank (copy) the characters of the word from the cursor position to the start of the next wordyiw— Yank (copy) word under the cursoryaw— Yank (copy) word under the cursor and the space after or before ity$orY— Yank (copy) to end of linep— Paste after cursorP— Paste before cursorgp— Paste after cursor and leave cursor after the new textgP— Paste before cursor and leave cursor after the new textdd— Delete (cut) a line2dd— Delete (cut) 2 linesdw— Delete (cut) the characters of the word from the cursor position to the start of the next worddiw— Delete (cut) word under the cursordaw— Delete (cut) word under the cursor and the space after or before it:3,5d— Delete lines starting from 3 to 5:g/{pattern}/d— Delete all lines containing pattern:g!/{pattern}/d— Delete all lines not containing patternd$orD— Delete (cut) to the end of the linex— Delete (cut) character
Registers
:reg[isters]— Show registers content"xy— Yank into register x"xp— Paste contents of register x"+y— Yank into the system clipboard register"+p— Paste from the system clipboard register
Special registers:
0— Last yank"— Unnamed register, last delete or yank%— Current file name#— Alternate file name*— Clipboard contents (X11 primary)+— Clipboard contents (X11 clipboard)/— Last search pattern:— Last command-line.— Last inserted text-— Last small (less than a line) delete=— Expression register_— Black hole register
Search and Replace
/pattern— Search for pattern?pattern— Search backward for pattern\vpattern— ‘Very magic’ pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed)n— Repeat search in same directionN— Repeat search in opposite direction:%s/old/new/g— Replace all old with new throughout file:%s/old/new/gc— Replace all old with new throughout file with confirmations:noh[lsearch]— Remove highlighting of search matches
Search in Multiple Files
:vim[grep] /pattern/ {file}— Search for pattern in multiple files- Example:
:vim[grep] /foo/ **/*
- Example:
:cn[ext]— Jump to the next match:cp[revious]— Jump to the previous match:cope[n]— Open a window containing the list of matches:ccl[ose]— Close the quickfix window
Working with Multiple Files
:e[dit] file— Edit a file in a new buffer:bn[ext]— Go to the next buffer:bp[revious]— Go to the previous buffer:bd[elete]— Delete a buffer (close a file):b[uffer]#— Go to a buffer by index #:b[uffer] file— Go to a buffer by file:lsor:buffers— List all open buffers:sp[lit] file— Open a file in a new buffer and split window:vs[plit] file— Open a file in a new buffer and vertically split window:vert[ical] ba[ll]— Edit all buffers as vertical windows:tab ba[ll]— Edit all buffers as tabsCtrl+ws— Split windowCtrl+wv— Split window verticallyCtrl+ww— Switch windowsCtrl+wq— Quit a windowCtrl+wx— Exchange current window with next oneCtrl+w=— Make all windows equal height & widthCtrl+wh— Move cursor to the left window (vertical split)Ctrl+wl— Move cursor to the right window (vertical split)Ctrl+wj— Move cursor to the window below (horizontal split)Ctrl+wk— Move cursor to the window above (horizontal split)Ctrl+wH— Make current window full height at far leftCtrl+wL— Make current window full height at far rightCtrl+wJ— Make current window full width at the very bottomCtrl+wK— Make current window full width at the very top
Exit
:w— Write (save) the file, but don’t exit:w !sudo tee %— Write out the current file using sudo:wqor:xorZZ— Write (save) and quit:q— Quit (fails if there are unsaved changes):q!orZQ— Quit and throw away unsaved changes:wqa— Write (save) and quit on all tabs
Misc
:h[elp] keyword— Open help for keyword:sav[eas] file— Save file as:clo[se]— Close current pane:ter[minal]— Open a terminal windowK— Open man page for word under the cursor