Blog Logo

My (Neo)Vim Cheat Sheet

Table Of Contents

I love Vim because I can do everything with the keyboard. The downside, is that you have to do everything with the keyboard.

In case you didn’t get the pun, the real problem is that you have to memorize a bunch of commands and key combinations to to do things like delete a line in the current text or how to format the current buffer.

To aid myself on memorizing this commands I created this cheat sheet that works with my configuration.

If you want something more complete, graphical and generic, you can visit the Graphical vi-vim Cheat Sheet and Tutorial site.

One thing tough. I try to use the default key-maps as much as I can, so this cheat sheet might still be useful to you in case you want to create you own.

Movements and insert

This commands are for normal mode:

CommandAction
wBeginning of the next word
bBeginning of the previews word
eEnd of the next word
oTo get to the other end of the selection
$End of line
f<char>Go to forward to the next character. Pe. fx
{Go to previous paragraph (empty line)
}Go to next paragraph (empty line)
AAdd text at the end of the line
IAdd text at the beginning of the line
zzPlace the current line in the middle of the editor window
z<enter>Place the current line at the top of the editor window

Advanced movement commands

All this commands are for normal mode:

CommandAction
ggGo to beginning of file
GGo to end of file
<C-f>Page Down (Page Forward)
<C-b>Page Up (Page Backward)
gdGo to definition of word or function in current file
gfTo to definition in other file
<number>GGo to line <number>. P.e. 16G
<C-o>Previous position or previous buffer (useful when using gd or gf)
<C-i>Next position or next buffer

Advanced save

This commands are for normal mode:

CommandAction
<number1>,<number2>w file-name.txtSaves lines to a new file. P.e. 12,43w
:r <file-name.txt>Inserts contents of file-name.txt in current position

Delete Undo/Redo

This commands are for normal mode:

CommandAction
xCut (Works in visual mode too)
sCut (Substitute) char and place in insert mode
deDelete to end of word
d0Delete to the beginning of the line
dbDelete back
df<char>Delete until the next <char>. P.e dfx
:.,$dDelete until the end of the buffer
uUndo
UUndo on the whole line
<C-r>Redo

Repeat

Most commands, when preceded by a number, are executed multiple times:

CommandAction
6dwDelete next 6 words
6ddDelete next 6 lines
.Redo last change action
;Redo last character find f{char}

Clipboard

CommandAction
y<movement>Copy (Yank). <movement> can be h, j, l, k, w, e, $, 0
pPaste it after the cursor
ddDelete line
OPaste over the current line
PPaste under the current line

Registers

It’s like a clipboard history

CommandAction
:reg, :reg [char]List registers. Show contents of one register
"<number>pPaste contents of register. P.e. "2p Pastes register 2
<C-r><char>Paste the contents of register in insert mode
""The register used when Copy (y), Cut (x) or Substitute (s)
"0-"9Last yanked elements being "0 the newest ( "0p is the same as p)
"%Current file path starting from the project root

Changes

CommandAction
rReplace current character
ROverwrite content (replace) until you escape
ciwChange Inside word no matter the position
cipChange Inside paragraph (between empty lines) no matter the position
ci)Change (inside) the contents until the next )

Folding

CommandAction
ziFold enable
zf2jFold the next 2 lines (depends of the fold type)
:20,40 foFold from line 20 to 40
zfa}Fold until the next }
zo zOOpen current fold. Open recursively
zc zCClose current fold. Close recursively
za zAToggle current fold. Toggle recursively
zm zMReduce fold level by one. Close all folds
zr zRIncrease fold level by one. Increase recursively
CommandAction
/Search
?Search backwards
*Search for the word under the cursor
nNext result
NPrevious result

Search & Replace

CommandAction
:s/original/new/gSearch and replace in the complete line
:%s/original/new/gcSearch in all document asking if do the change (c)

Visual

CommandAction
vStart the visual (Use jkhl to move the selection)
v$Select until the end of line
vipSelect current paragraph (content between empty lines)
VVisual the complete line (Use jk to move the selection)

Splits

CommandAction
:sp, :vsSplit and Vertical split
:onlyFocus on a splt
giOpen in split in NERDTree

QuickFix and Location List

CommandAction
:copenOpen error list
:ccloseClose error list
:cnextGo to next error

Debug utilities

CommandAction
Ctrl-gShow file status
:verbose imap <tab>Find if the <tab> key is defined
:verbose imap <C-p>Find if the <ctrl>p key is defined
:lopen, :lcloseOpen/closes the location list. Used by plugins like ALE to show a list of errors
:copen, :closeOpen/Closes/Focuses the list of errors

Native Autocomplete

CommandAction
<C-x><C-p>Autocomplete with an already present word

Sessions

CommandAction
:mks <path>Saves the current session to a path. Better if it’s a hidden dir

Markers and Macros

CommandAction
m<character>Creates a marker with the name <character
'<character>Jumps to marker. (Use backtick to include column )

Spell

Spell needs to have set spell option active on .vimrc and optionally use set spelllang=en_us. I use es_co for Spanish Colombia.

CommandAction
z=Search for alternatives of the current word
zgAdd current word to dictionary
zwRemove current word from dictionary
]sJump to next spell error
[sJump to previous spell error

Plugins

NERDTree Commands

This are particular to my configuration

CommandAction
<C-k><C-k>Toggle NERDTree (open if closed, close if open)
<C-k><C-f>Toggle NERDTree and select the current file

This commands are to be executed while inside the NERDTree sidebar:

CommandAction
sOpen on left
vsOpen on top
tOpen on new tab

NERD Commenter

This are the default key-maps

CommandAction
<leader>c<space>Toggle comments
<leader>ciToggles the comment state of the selected line(s) individually.
<leader>csToggle sexy Comments out the selected lines with a pretty block formatted layout.

FZF Commands

Its really helpful to use :help fzf-vim-comands to browse the documentation

CommandAction
:BCommitsCommits for the current buffer (Requires Fugitive)
:CommandsSearchable list of ALL commands
:GFilesIgnores files in .gitignore
:HistoryOpens up the list of last edited files
:Rg!Like grep for all the project files but faster
:SnippetsUtilSnips snippets
:TagsTags in the project
<C-k><C-u>Executes :Buffers
<C-6>Loops through the 2 most recent buffers

GitGutter

CommandAction
:GitGutterToggleShow/Hide file changes
[cShow next block of changes
]cShow previous block of changes
<Leader>huRemove hunk
:GitGutterFoldToggle fold of the file changes

Fugitive

This commands are to be executed on the :Gstatus window

CommandAction
g?Show help
=Toggle small diff of the file under the cursor
-Toggle stage/unstage file under cursor
dvDiff split vertically
<leader>gsToggle Status (my .vimrc)

CoC commands

This commands assume you used the example configuration suggested by the CoC GitHub page

CommandAction
:FormatCode beautify
:FoldFold functions
:OROrganize Imports
:CocConfigOpen the configuration file
:CocInstall <plugin name>Install a new CoC plugin

Vim-Surround

A complete tutorial can be viewed here

CommandAction
ys<motion><char>You surround. Pe, ysiw', ysa2w"
cs<char><char>Change surrounding. Pe. cs'" Change surrounding ' with ". Or cstt change tag with another tag
ds<char>Delete surrounding. Pe. ds' Remove surrounding quote. dst will delete a tag
dWDelete word including it’s surrounding space
yss<char>The line. Pe yss" Surround the line with "
yssf, ysiwfYou surround with a function (It will prompt you for the function name). iw its inside a word
ysst, ysiwtYou surround with an html tag. (it will prompt you for the tag)
ysas"You surround a Sentence
ySSurround a motion and adds a line afterwards. Pe. ySi2w(
ySSSurround the complete line and add a line afterwrds. Pe ySS(

In visual mode

CommandAction
SSurround the selected words
gSSuppress auto indent

Aliases

CharAlias
)b
}B
]r
>a
_ (space)s
< (html)t
fFunction