Vim motions and commands
These are Vim motions I actually use in (mostly) the order I learned them.
The basics
- Movement
h
-j
-k
-l
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
-
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 like at least 2 weeks.
Horizontal movements
These took me a while to get used to, more than vertical movements.
_
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>
forward to just before the character- For all
f
andt
:;
next one -,
previous one
- For all
o
new line below and go in insert modeO
new line above and go in insert mode
Vertical movements
<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 highlights
map("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