VIM: Cheat Sheet
I started with:
The basics
- Movement
h
-j
-k
-l
Hard mode:
map('n', '<left>', '<cmd>echo "Use h to move!"<CR>')map('n', '<right>', '<cmd>echo "Use l to move!"<CR>')map('n', '<up>', '<cmd>echo "Use k to move!"<CR>')map('n', '<down>', '<cmd>echo "Use j to move!"<CR>')
-
Insert
i
anda
. Also with capital to beginning and end of lineI
A
-
o
new line below and go in insert mode -
O
new line above and go in insert mode -
Activate relative line numbers and use counts:
C<hjkl>
-
w
word forwards andb
word backwards -
d
delete- Combine with words:
dw
- Combine with movement
5dj
- Combine with words:
-
y
to yank/copy andp
to past -
ciw
[c]hange [i]nner [w]ord -
ciW
[c]hange [i]nner [W](contiguous piece of text)
Stop here. Spend a lot of time just on these. Don’t do more for min 2 weeks.
Horizontal movements
These took me a while to get used to, more than vertical movements.
_
/0
beginning of line,$
end of linef<char>
[f]orward to the charactert<char>
forward to just before the characterF<char>
backwards to the characterT<char>
backwards to just before the character- For all
f
andt
:;
next one -,
previous one
Combinations:
dt"
: [d]elete un[t]il [”]vt$
: [d]elete un[t]il [“]
Vertical movements
Move quickly:
<C-d
> half page up and<C-u>
help page up
-- better move page up and down (keep cursor in the middle)map("n", "<C-d>", "<C-d>zz")map("n", "<C-u>", "<C-u>zz")
-
G
all the way to the bottomgg
all the way top- I usually confuse them
-
/
search forward?
search backwards- Move to
n
next andN
previous
- Move to
-- Remove search highlightsmap("n", "<Esc>", ":noh<return><esc>")map("n", "<C-c>", ":noh<return><esc>")
*
on top of a word makes it search that word forwards and#
backwards. Just do*
andN
to go backwards
Advanced
- Select inside something
- Select a word
viw
- You can be anywhere in the word - Select everything inside
{}
=vi{
- Select everything inside
{}
(including them)=va{
- Works with yank as well:
yi{
Copy everything inside{}
- Select a word
o
in Visual mode toggles the position from top to bottom