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 movek aroundl |
d deletec change< > indentv 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 insertI insert start of linea insert after cursorA insert end of lineo insert on new line belowO insert on new line above |
yl yank charyw yank wordyy Y yank linep paste after current lineP paste before current line |
dl delete chardw delete worddd delete linex 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 charcw change wordcc change lineC change from cursor to end of linesl change charS change line |
r replace single charR replace until stop typing~ change char case |
u undoU 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 ofi
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. Doingva(
will include the brackets.
Commands Link to heading
Find, Save, Quit Link to heading
Find | Save/Quit |
---|---|
/ ? search forwards/backwardsn next hitN prev hit |
:w save:q quitZZ 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
toz
instead ofr
, 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
.