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
ianda. Also with capital to beginning and end of lineIA -
onew line below and go in insert mode -
Onew line above and go in insert mode -
Activate relative line numbers and use counts:
C<hjkl> -
wword forwards andbword backwards -
ddelete- Combine with words:
dw - Combine with movement
5dj
- Combine with words:
-
yto yank/copy andpto 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.
_/0beginning 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
fandt:;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")-
Gall the way to the bottomggall the way top- I usually confuse them
-
/search forward?search backwards- Move to
nnext andNprevious
- 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*andNto 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
oin Visual mode toggles the position from top to bottom