Vim Cheatsheet ⱈ
Baby Steps
hmove cursor to the leftjmove downkmove uplmove rightiGo into Insert mode<ESC><C-C><C-[>Go back to Normal mode
Move Fast Word by Word
wmove to the beginning of next wordbmove to the beginning of the previous wordemove to the end of the next word-
gemove to the end of the previous word Wmove to the beginning of next WORDBmove to the beginning of the previous WORDEmove to the end of the next WORDgEmove to the end of the previous WORD
Find Character
f{character}Find next occurrence of character-
F{character}Find previous occurrence of character t{character}Find next occurrence of character and place cursor just before it-
T{character}Find previous occurrence of character and place cursor just before it ;Go to next occurrence of {character},Go to previous occurrence of {character}
Move Extremely Horizontally
0Moves to the first character of a line^Moves to the first non-blank character of a line$Moves to the end of a lineg_Moves to the non-blank character at the end of a line
Move Faster Vertically
}Jumps entire paragraphs downwards{similarly but upwardsCTRL-Dlets you move down half a page by scrolling the pageCTRL-Ulets you move up half a page also by scrolling
High Precision Vertical Motions with Search
/{pattern}Search for {pattern}. {pattern} is a regex.-
?{pattern}Search for {pattern} backwards. /Repeat last search forwards-
?Repeat last search backwards nGo to next matchNGo to previous match
Move Faster with Counts
-
{count}{motion}Repeat {motion} {count} times 2wJump to second word4f"Jump to fourth occurrence of the “ character3/cucumberJump to third match of “cucumber”
Move Semantically
gdGo to definition (of the word under the cursor)gfGo to file (for file under the cursor)
More Nifty Core Motions
ggGo to the top of the file{line}ggGo to {line}GGo to the end of the file%jump to matching ({[]})
Edit Like Magic With Vim Operators
-
{operator}{count}{motion}Apply operator on bit of text covered by motion ddeletecchangeyyank (copy)pp (paste)g~switch case>shift right<shift left=format
Linewise Operators
dddelete a lineccchange a lineyyyank (copy) a lineg~~switch case of a line>>shift line right<<shift lineleft==format line
Capital case (Stronger version) Operators
Ddelete from cursor to the end of the lineCchange from cursor to the end of the lineYyank (copy) a line. Like yyPput (paste) before the cursor
Text objects
{operator}a{text-object}Apply operator to all text-object including trailing whitespace-
{operator}i{text-object}Apply operator inside text-object diwdelete inner worddawdelete a worddisdelete inner sentencedasdelete a sentencedipdelete inner paragraphdapdelete a paragraphdi(dibdelete inside parenthesesda(dabdelete text inside parentheses (including parentheses)di{diBdelete inside bracesda{daBdelete text inside braces (including braces)di[delete inside bracketsda[delete text inside brackets (including brackets)di"delete inside quotesda"delete a quoted text (including quotes)ditdelete inside tag-
datdelete a tag (including tag) ciwsame goes for other operators…
Repeat Last Change
.Repeat the last change
Character Editing Commands
xdelete a character. Like dlXdelete character before the cursor. Like dhschange a character. Like cl~switch case of a character
Undo and redo
uundo last changeC-Rredo last undo{count}uundo last {count} changes
Inserting Text
igo into insert mode before the cursor-
ago into insert mode after the cursor Igo into insert mode at the beginning of a line-
Ago into insert mode at the end of a line oinsert new line below current line and go into insert mode-
Oinsert new line above current line and go into insert mode -
gigo to the last place you left insert mode C-Hdelete last characterC-Wdelete last wordC-Udelete last line
Visual Mode
vgo into character-wise visual modeVgo into line-wise visual mode-
C-Vgo into block-wise visual mode (to select rectangular blocks of text) {trigger visual mode}{motion}{operator}Visual mode operates in kind of the opposite way to normal mode. First you specify the motion to select text, and then you apply the operator
Operate on Next Search Match
-
{operator}gnApply operator on next match -
.After using {op}gn, the dot commant repeats the last change on the next match. Woooot!
Copying and pasting
y{motion}yank (copy) text covered by motionpput (paste) after cursor-
Ppaste before cursor yycopy line-
Ycopy line yypduplicate lineddpswap lines-
xpswap characters "ay{motion}copy to register a"Ay{motion}copy and append to register a-
"appaste from register a "unnamed register0yank register1-9delete registers-
[a-z]named registers C-R apaste from register a when in Insert mode
Command-line mode
:edit {file}:e {file}create or edit file:write:wsave file:quit:qclose file:write!:w!force save file:quit!:q!close file without saving:wqsave and close file:wall:wasave all files:qall:qaclose all files:wqall:wqasave and close all files-
:qall!:qa!close all files without saving -
:[range]delete [register]:[r]d [r]delete multiple lines into register @:repeat last ex command@@after repeating it once, you can continue repeating with this
Command-line mode Ranges
:{start},{end}start and end lines of range e.g. :1,2d:{start},{offset}start and offset lines of range e.g. :1,+2d.current line e.g. :.,+2d%whole file e.g. :%d0beginning of file e.g. :0,10d$end of file e.g. :10,$d:'<,'>visual selection
Command-line mode Substitute
-
:[range]/{pattern}/{substitute}/[flags]substitute matched pattern for string literal in given range g flagsubstitute all matches in a linei flagcase insensitive searchc flagconfirm substitution for each match
Split Windows
:sp {file}Open file in a horizontal split-
:vsp {file}Open file in a vertical split C-W SOpen same file in a horizontal split-
C-W VOpen same file in a vertical split C-W hMove to split to the leftC-W jMove to split belowC-W kMove to split aboveC-W lMove to split to the right
Tabs
:tabnew {file}Open file in new tab:tabnext:tabnJump to next tab:tabprev:tabpJump to previous tab:tabonly:taboClose all other tabs
Vim surround
dsdelete surroundings e.g. ds”cschange surroundings e.g. cs*tem>-
ysadd surroundings e.g. ysiw” ds"delete surrounding quotescs*tem>change surrounding * for the tag-
ysiw"surround word under the cursor with quotes SIn visual mode you can select some text, then type S to add surroundings. e.g. Stp> to wrap the selection in a <p> tag
Custom mappings (they need to be added to your config)
Insert mode
jkGo back to normal mode
Normal mode
JGo down fasterKGo up faster<leader>jJoin lines<leader>/Clear highlighted text-
<leader>wSave file <leader>pOpen command palette-
<leader>tGo to symbol in file <C-H>Move to the window on the left<C-J>Move to the window below<C-K>Move to the window above-
<C-L>Move to the window on the right <leader>ttCreate new tab<leader>tnMove to next tab<leader>tpMove to previous tab<leader>toClose all tabs but the current one
Moving Faster with Vim-sneak
s{char}{char}Jump to the next ocurrence of {char}{char}S{char}{char}Jump to the previous ocurrence of {char}{char};Go to next occurrence of {char}{char},Go to previous occurrence of {char}{char}{op}z{char}{char}Apply operator on text traversed by vim sneak motion
Moving Faster with Easymotion
<leader><leader>wstart of words<leader><leader>bstart of words backwards<leader><leader>bdwstart of words everywhere. The bd stands for bidirectional<leader><leader>eend of words<leader><leader>geend of words backwards<leader><leader>bdwend of words everywhere<leader><leader>jbeginning of lines<leader><leader>kbeginning of lines backwards<leader><leader>f{char}find character<leader><leader>F{char}find character backwards<leader><leader>t{char}until character<leader><leader>T{char}until character backwards<leader><leader>s{char}search character everywhere
Multiple Cursors
Based on Search
<CMD-D><C-D>gbAdds an additional cursor. This command puts you in visual mode. In effect, it selects all the words under each new cursor at once.{operator}Applies operator on words selected by the multiple cursors.IInsert before multiple words at the same timeAAppend after multiple words at the same time
In Consecutive Rows
<C-V>Go into Visual-block mode and select text using motions{operator}Applies operator on visual selection.IInsert before visual selectionAAppend after visual selection
Reusable Editing with Macros
q{register}Start recording a new macro in {register}qStop recording macro@{register}Replay macro in {register}@@Replay the last macro that you executed
Integrating with Neovim
:[range]copy {address}Copy lines after {address} line:[range]move {address}Move lines after {address} line:[range]normal {commands}Apply normal mode commands on a range of lines:execute "{ex-command}"Execute string as an Ex command. Useful in combination with normal when the normal mode commands include special characters.:[range]global/{pattern}/{command}Execute an Ex command on lines within a range that match a pattern. The default range is the whole file. Really useful in combination with the normal command.:[range]global!/{pattern}/{command}Execute an Ex command on lines within a range that do not match a pattern.
Some Handy VSCode Only Mappings
afSelect increasingly bigger blocks of textghEquivalent to hovering the mouse over a bit of text.
Bonus 01: Entire and Arguments Text Objects
daeDelete complete bufferyaeYank complete bufferciaChange function argumentdaaDelete function argument including separator