This is my vim cheat sheet 🚀

Basics Link to heading

Syntax of commands is broken into number + verbs + nouns. So for example 2dw means, delete two words:

2 for two
d for delete
w for word

Basic verbs Link to heading

Basics Verbs
h
j move
k around
l
d delete
c change
< > indent
v V visual select *
y yank

* : the latter (V) selects whole lines.
* : u U to lower/upper case selection in visual mode.
* : o in visual mode will move the cursor from beginning to end.

Basic Nouns (movements) Link to heading

Horizontal Movements Vertical Movements
w W forward 1 word *
b B backwards 1 word *
e E to last character in current word *
ge gE to end of previous word *
0 $ front and end of line
^ first non-whitespace char in line
% to matching brace, bracket, etc…
gg G beginning/end of doc
{ } up/down 1 paragraph
<c-u> <c-d> up/down ½ page
* # to next/previous instance of the same word
f<?> F<?> go on top of next/prev <?> **
t<?> T<?> go to next/prev <?> **
; , next/previous go to

* : the latter (W, B, E, gE) use whitespace as boundaries.
** : <?> can be any character.

Add, Copy, Paste, Cut, Delete Link to heading

Add Copy/Paste Cut/Delete
i insert
I insert start of line
a insert after cursor
A insert end of line
o insert on new line below
O insert on new line above
yl yank char
yw yank word
yy Y yank line
p paste after current line
P paste before current line
dl delete char
dw delete word
dd delete line
x delete char (same as dl)
X delete char before cursor

Note: Deletions always work like cut, that is, deleted object is put into a register so that it can be pasted later.

Change, Replace, Undo, Repeat Link to heading

Change Replace Undo/Repeat
cl change char
cw change word
cc change line
C change from cursor to end of line
sl change char
S change line
r replace single char
R replace until stop typing
~ change char case
u undo
U undo current line
<c-r> redo
. repeat command

More Nouns Link to heading

Nouns / Movements
iw inner word (select whole word)
it inner tag (select inside tag)
ip inner paragraph
i" i' inner quotes
a{ brackets and everything inside

Note: Use a instead of i in these examples to include whitespaces or surrounding symbol.

Note: Doing these outside selected pair will jump to next one. For example doing vi( outside a () pair will jump to the next ( and select everything inside those brackets. Doing va( will include the brackets.

Commands Link to heading

Find, Save, Quit Link to heading

Find Save/Quit
/ ? search forwards/backwards
n next hit
N prev hit
:w save
:q quit
ZZ save and quit

Replace/Delete Link to heading

Command
:s/<old>/<new> replace old with new on selected lines
:%s/<old>/<new>/g replace old with new globally
:%s/<old>/<new>/gc replace old with new with confirmation
:s/\(\d\+\)/number \1 using regex capture groups
:g/<pattern>/d delete line matching pattern

Bash Link to heading

Command
:!grep "find this string" %

Note: The file you have opened is % in this example!

Macros Link to heading

Create Apply View
qr start recording *
do anything when recording
q in normal mode to finish
@r apply macro :reg r look at r register
:reg look at all registers

* : You can use any letter a to z instead of r, these are just register names!

Clipboard & Buffers Link to heading

Clipboard Buffers
"+p paste from clipboard *
"+yy yank line to clipboard *
:ls list buffers
:b <?> switch buffer **
:bd <?> close buffer **

*: The clipboard is the + register. To access a register you start with ".
**: <?> is optional and can be a number or part of name.

Cursor Link to heading

Multicursor edit Cursor Position
e.g. commenting out 4 lines would be:

0 go to beginning of line
<c-v> enter visual block mode
3j also select next 3 lines
I insert at beginning
// add comment
<ESC> exit insert mode
H M L move cursor to top/middle/bottom of screen
zt zz zb scroll so cursor is on top/middle/bottom

Windows Link to heading

Create Manipulate Navigate
<c-w>s split (horizontally)
<c-w>v split vertically
<c-w>o close others
<c-w>c close
<c-w>H
<c-w>J move window
<c-w>K around
<c-w>L

<c-w>x swap positions
<c-w>h
<c-w>j move cursor
<c-w>k around windows
<c-w>l

<c-w>w move to next

Misc Link to heading

Netrw Misc
:Ex open netrw
% create file in netrw
:so source open file
<c-a> increment number

Plugins Link to heading

Kickstart your nvim configuration with kickstart.

Commands
:Telescope keymaps search in keymaps
:GenTocGFM generate markdown toc
:Mason list tools (i to install)
Navigation
<leader>sf search files
<leader>sg grep files
s jump forward/backward/to other windows

Note: Jump commands come from the Flash plugin.

Code
gd go to definition *
gr go to references *
gc<motion> comment out selection
= auto indent selection, i.e. =ap, =G
K Display symbol info

* : Select up and down with <c-p> and <c-n>.

Quick lists Link to heading

Quick lists are useful when searching for a word in your project, and get a list of all the files containing that word.

You can open up quick list of all the files in your project containing foo by opening up telescope, searching for foo and pressing <c-q>.

Then replace foo with bar by running :cdo s/foo/bar/ | update. Close all buffers opened by this command by running :cfdo bd.