I got pretty proficient at vim using basically the defaults (I added tabs to spaces and tab width to 4 spaces, and auto/smart indent in the .vimrc). These are the keys I use regularly. If you can memorize these, you can use vim proficiently: h/j/k/l (movement keys)
i (insert mode)
esc (leave current mode/go to default state)
u (undo)
>> / << (indent, unindent)
dd (delete line)
yy (copy line)
p (paste)
v (visual mode, used to highlight stuff)
gg (go to beginning of file)
G (go to end of file)
r (replace the char under the cursor with the next char entered)
% (jump to next paren/bracket, or if on a paren/bracket, jump to matching paren/bracket)
w (go to next word)
dw (delete word)
cw (change word (deletes the word then goes into insert mode))
A (append (goes to the end of the line and into insert mode)
0 (go to beginning of line)
$ (go to end of line)
/some_word (searches for some_word, hit n to jump to the next occurrence)
?some_word (searches for some_word, in reverse direction)
Common commands: :%s/regex/replacement/g (replace regex matches with replacement)
:q (quit)
:q! (quit without saving)
:w (save)
:wq (save then quit)
:x (save then quit)
:set blah (turns on setting blah)
:set noblah (turns off setting blah)
Most vim commands you can stick a number N before to execute N times.e.g. 5d deletes 5 lines. 5y copies 5 lines. 5> indents 5 lines. 5j jumps down 5 lines. Some common command combinations: %v%> (jump to next bracket, go into visual mode, jump to next bracket (highlighting everything in between), then indent it all)
ggdG (jump to top, then delete everything to the end of file, (clears a file))
ddp (deletes a line of text and then pastes it (below where it currently it), thus this transposes two lines)
You can see how you quickly develop strings of commands you rattle off by chaining basic commands together.EDIT (joke): Q. How do you algorithmically generate a cryptographically strong random string? A. Put a newbie in front of vim. |
So you can be anywhere inside a quote and do "change inside quotemark" and it'll delete everything inside and leave you in insert mode. "around" would delete everything inside and the quotemarks.
These can be used with other things, parentheses, square brackets (and I think some plugins extend it to html tags and the like).
Of course, you can swap out c for d, y or any of the other verbs.
Working in clojure and deleting everything inside a particular level of nested parentheses is awesome.