[Tools] VIm cheat sheet
Keep this handy as you experiment with vim:
http://www.fprintf.net/vimCheatSheet.html
Here is another guide that covers the commands incrementally:
http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
In insert mode, the arrow keys do work, but you should practice not using them!
Instead, in command mode:
- h - moves left one character
- j - moves down one line
- k - moves up one line
- l - moves right one character
You can move all kinds of places quickly in command mode:
- ^ or 0 - move to the start of the current line
- $ - move to the end of the current line
- gg - jump to the beginning of the file
- G - jump to the end of the file
There are so many ways to delete!
- x - delete the character under the cursor
- dd - delete the current line
- d$ or D - delete from the cursor to the end of the current line
- d0 or d^ - delete from the cursor to the start of the current line
You'll notice that we've already seen 0
and $
before! You can repurpose each of the moving around commands to delete text. These all work:
- dG - delete from the current position to the end of the file
- dgg - delete from the current position to the start of the file
- dj - delete the current line and the line below
- dk - delete the current line and the line above
- 2dd, 3dd etc - delete the next N lines
Even dl
and dh
work!
Remember that vim is a language!
searching
You can search for text using regular expressions.
- /PATTERN - search forward for PATTERN
- ?PATTERN - search backward for PATTERN
Press:
- n - jump to the next match
- N - jump to the previous match
PATTERN is a regular expression, but you can just treat it as an ordinary text match for the most part.
You can combine searching with deleting too:
- d/PATTERN - delete to the next match of PATTERN
- d?PATTERN - delete to the previous match of PATTERN
- dn - delete to the next already matched pattern
- dN - delete to the previous already matched pattern
You can also skip ahead to individual characters in a simple way on the current line:
- f + CHAR - search forward on the current line to CHAR
- t + CHAR - search forward on the current line to the character before CHAR
- F + CHAR - search backward on the current line to CHAR
- T + CHAR - search backward on the current line to the character after CHAR