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 wordgemove to the end of the previous wordWmove 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 characterF{character}Find previous occurrence of charactert{character}Find next occurrence of character and place cursor just before itT{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 backwardsnGo to next matchNGo to previous match
Move Faster with Counts
{count}{motion}Repeat {motion} {count} times2wJump 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 motionddeletecchangeyyank (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-objectdiwdelete 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 tagdatdelete 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 cursorago into insert mode after the cursorIgo into insert mode at the beginning of a lineAgo into insert mode at the end of a lineoinsert new line below current line and go into insert modeOinsert new line above current line and go into insert modegigo to the last place you left insert modeC-Hdelete last characterC-Wdelete last wordC-Udelete last line
Visual Mode
vgo into character-wise visual modeVgo into line-wise visual modeC-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 cursorPpaste before cursoryycopy lineYcopy lineyypduplicate lineddpswap linesxpswap 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 registersC-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 rangeg 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 splitC-W SOpen same file in a horizontal splitC-W VOpen same file in a vertical splitC-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 <em> tagysiw"surround word under the cursor with quotesSIn 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)
jkGo back to normal modeJGo 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
Insert mode
Normal mode
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
<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<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
Based on Search
In Consecutive Rows
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
