You only need to know a few basic pure motions, mostly for moving around: h/j/k/l, gg, G, <count>G, 0/^, $, <C-o>/<C-i>, <c-d>/<c-u>
The more important motions are %, f/t and the text-objects (:help for a full description). These are the vim power tools and honestly what I use ~80% of the time.
The f<char> motion moves forward on the same line up through <char>. The t<char> motion (mnemonic: 'til) works the same but doesn't include <char>. Capitalize to go backwards. You can string this together to get all sorts of useful behavior: change startFoo to stopFoo (ctF), work with TSV (ct<tab>), not have to remember W (ct<space>), etc. I tend to overuse it for things like deleting everything but the semicolon on a line so I don't have to retype the semicolon...but you get the point.
The % motion jumps between match pairs (parens, braces, etc), but the important trick with it is that if you're not on a pair, it searches forward till it finds one. This is mostly useful for manipulating function calls and email addresses, e.g. d% deletes a call if you're at the beginning of the function name. Pretty specific use but common use case.
Then there's text objects. You mentioned a couple use cases, but they're more general. There's two transitions, i (diw "delete inner word") and a (daw "delete a word"). Most text objects are marked by delimiters (e.g. parens, xml tags) a includes these i excludes them. There's a lot of ways to put these together, a few:
- ci[ : replace contents of an array access
- da[ : delete the array access
- ci" : replace contents of a string
- dat : delete an XML tag
- =i{ : realign the current block
- zfab : fold sexpr
- gqap : wrap paragraph
What makes the motions I mention here particularly great is that they tend to generalize well when you repeat them with period and don't rely on you pre-counting a certain number of words, lines, or whatnot.
If you're consistently using these motions, you're most of the way there to being a vim expert. The rest is all tricks. You can find your own tricks by noticing when you're repeating yourself or using too many keystrokes. In general, if you're using more than 5-6 keystrokes to do something, there's a shorter way to do it. The shorter way isn't necessarily worth the conceptual overhead, but you'll learn a bit more. You never really stop learning them, but it gets hard to remember once you've been using Vim daily for 5+ years (I'm 10 years in).
The most important plugin for tricks is surround.vim. You should immediately install it and add the following mappings:
nmap s ysi
nmap S ysa
nmap s$ ys$
nmap sv gvs
This lets you operate in 'surround' motions around text objects. E.g. sw( will surround the current word with parens, sp" surrounds the paragraph with quotes. You can change single quotes to double quotes: cs'" and so on. The sv map here surrounds the previous visual selection, I use it when I'm doing multiple wraps: sw'sv[sv(
Random useful tricks (there are thousands of these):
gv selects the previous visual selection. You can V select a number of lines, type colon and replace only in the selected area, then gv to do a < or :retab! or :g/^$/d or something.
Check out :help iskeyword, doing a :set iskeyword+=- is useful in CSS, XML, lisp.
The vim regex engine is screwy. Pretty much everybody knows this (sigh \+), but it's screwy in useful ways too. When you're doing a replacement, \zs and \ze mark the start/end of the match. If, for example you want to insert something at the end of all strings, :%s/"[^"]\+?\zs\ze"/ foo/g. Saves you from having to do capture groups/backrefs and whatnot. Also, the \k character class matches "keywords" (identifiers) for your current language and it's smart \<\k\+\> will not match numbers, for example.
If you have incsearch and hls turned on and are working on a tricky regex replace, it's useful to drop out and start oa normal search with / to see your matches highlighted. When you get your match, :%s//replace/g will reuse your search.
Know asterisk and # if you don't already.
You can save a location using m<letter> and jump back to it using `<letter>. Lowercase is in-file and uppercase is global. I tend to mA when I go looking for something elsewhere so I can get back to what I'm working on easily with `A. You can bounce back to where you just jumped from with ``, but I think <c-o> and <c-i> work better for that.
Random vimrc tricks:
"make Y consistent with C and D
nnoremap Y y$
" I use splits (tabs came later). `vim -o *.c'
nmap - :Sexplore<CR>
map <C-j> <C-W>j<C-W>_
map <C-k> <C-W>k<C-W>_
"repeats the last command for the entire visual selection
vnoremap . :normal .<CR>
"executes the macro in buffer a
nnoremap ' @a
vnoremap ' :normal @a<CR>
"Look up vim ToggleFold on google
nnoremap <silent> <space> :call ToggleFold()<CR>
"mapping for paste toggle
noremap <silent> <Leader>p :se invpaste<CR>:echo &paste ?
"Paste ON!" : "Paste off"<CR>
" I think the default gp is stupid. This puts the cursor BEFORE the start of
" the paste and is primarily used for useful repeating: gpj.j.j.
nnoremap <silent> gp :<C-U>call repeat#exec("p`[h",1)<CR>