Don't let this list intimidate you, Vim allows you to learn at your own pace, I was mashing h,j,k, and l for years before I learned the beauty of grouping movements (e.g., 12j instead of j 12 times). I try to learn one new thing a week so I can commit it to muscle memory.
It seems like so much of power vim use is about jumping 3 characters ahead or 12 lines down.
Is this for real? Do you count the number of lines or characters before you move? Do you look at line numbers and do the arithmetic in your head? This can't be right, right?
> Do you count the number of lines or characters before you move?
I think most people use commands like f) (move to to the next ')' on the current line) more often than something like 12k (move twelve chars to the right), because, like you say, counting chars is slower than mashing 'k'.
People just use 12k because it's a simple example of how vim commands can be chained together. As a less-contrived example, you can do 2f) to move to the second ')' on the current line.
Personally I just estimate and correct. Usually I use numbers that are easy to type with the left hand so I can keep my right on the home row. If the place I'm moving to is 17 lines up, I'll likely get there with 15jjj. Even with relative line numbers turned on, that feels faster for me than stopping to look at the number. (Haven't timed it, but feeling fast keeps me in flow so that's my metric.)
Various semantic movements help a lot, too. But I never stress on hitting the target exactly, I'd rather get nearby without thinking than stop and think to get there in one command.
It's more about "semantic editing" than memorizing arcane keybinds. With Vim, you describe what you want to do with actions and motions. Motions move the cursor from a starting point to an end point and then actions do something with everything between the start and the end.
For example, if you want to delete 3 words, there is an action to delete (d) and a motion to move forward one word (w): 3dw (read (3) times, (d)elete (w)ord)
If you want to delete everything up to a closing bracket, there's a motion to move to the next occurrence of a character (t): dt)
(read (d)elete (t)o ')')
It becomes much more productive when you're thinking in terms of composing actions and motions to achieve a goal rather than memorizing situational key combos. The hardest part is getting over the hump of memorising the actions and motions.
Relative line numbers aren't even too important, given that there is a motion to jump to a line number. If you have a function that you can see starts at line 6 and ends at line 14 and I want to move it to the top of the file. You want to go to line 6 (6G), delete (d), go to line 14 (14G - thus applying the delete action to the motion of moving from line 6 to line 14) then go to line 1 (1G) and paste (P).
> For example, if you want to delete 3 words, there is an action to delete (d) and a motion to move forward one word (w): 3dw (read (3) times, (d)elete (w)ord)
I prefer to use d3w since it feels more like English. It's also more compatible with other combinations like ci" ('change inside quotes', e.g. to change a string), ca" ('change around quotes', e.g. to replace a string with a constant), or yt{ ('yank to brace').
% will bounce back/forth over matched pairs of (), [], {}. :/foo/z6 will move 6 lines after the line that matches "foo" (I know it's not eliminating counting). There are also word, sentence, and paragraph movement available.
I "bookmark" important lines with named markers "ma", "mb", etc for "a" and "b" markers respectively, available as 'a, 'b.
Not to mention cscope or ctags for finding function declarations, various call chains, etc., etc.
I use relative line numbers so I don't have to count, vim tells me how many lines are between my current cursor position and wherever I need to jump to.
Hah, I didn't think of that! Just before reading this comment I was working along in the editor, furiously pressing j/k. I'll put this to use immediately.
Yikes! The continually changing numbers drives me crazy. Thanks for the tip, but I think I'll stick with just using ":13" to go to line #13... I guess there is some benefit if you do a lot of yanking/cutting based on lines, rather than some magic matching or such. But for now, relative line numbers is not for me.
n jump to the next occurrence of the last search
N " " " previous " " " " " "
* jump to the next occurrence of the word under cursor
# " " " previous " " " " " "
Yes! Also, ^R^W (ctrl-r, ctrl-w) when you're at the : prompt will drop in the current word under the cursor. Which is also quite useful in keybindings.
Thanks. That's a great tip. I've always yanked the word that I wanted and then used Ctrl-R" to paste it on Vim's command line. This is much better.
I'm now off to read "cmdline.txt" (:help Command-line).
BTW, I just accidentally closed my browser tab (latest version of Firefox) by hitting Ctrl-W when I wanted to delete the previous word in this textbox. That used to drive me mad but when Firefox restored the tab, it also restored the text I'd typed. :)
or alternatively try the easymotion plugin[1] which you press <leader><leader>j (or whatever you map it to) and then it will highlight each potential line with a letter that you press to go to that line. j is one of the worst examples, it's nice if you are doing a dw so you don't have to count the words, you would just do d<leader><leader><motion> and it will highlight to the potential places.