-
Notifications
You must be signed in to change notification settings - Fork 3
VIM Cheat Sheet
Too exit out of VIM. Hit escape (one or more times) then type :q
To save. Hit escape (one or more times) then type :w
Command Mode - hit escape one or more times and you'll get here
Special Commands - typing the following characters enable some special command modes
- : - execute a vi command, it's like the tool bar for vi. so to save you type :w (write) and to quit :q
- / - find - odd regex syntax for vi unless you type /\v
- %s/ - substitute (find replace) %s/findexp/replacexp/gI where g is the whole doc and capital I is case sensitive and lower i is case insensitive
- ! - run whatever follows on the shell
Edit Mode - hit one of the edit keys in command mode and you get here. once you are in edit mode, it's just like notepad until you hit the escape key.
- i - insert
- o - open
- a - append
Visual Mode - hit v and then move around and it'll select text like you would with click and drag on the mouse. Whatever is selected can be copied, replaced, cut, deleted by typing the corresponding 'command' key (i.e. x for cut)
one letter at a time:
-
j - down
-
k - up
-
h - left
-
k - right
one word at a time:
- w - word forward
- e - end of word forward
- b - back a word
line:
- $ - end of line (just like regex)
- ^ - first non-white character (think regex)
- 0 - beginning of line
page down:
- ctl f - forward a page
- ctl b - backward a page
- i - insert, start editing wherever the carrot is
- o - open a line up (also shift o)
- a - append
- u - undo
- ctl r - redo
- x - delete single character
- p - paste (also shift p)
- d - delete + direction command
- y - copy aka yank + direction command
so you want to copy a word, combine the cut, copy, delete command with a navigation command:
yw - yank word dw - delete word
yy - yank whole line dd - delete whole line [shift]d - delete the rest of the line from the cursor [shift]y - yank the rest of line from the cursor