Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


I believe there is an option to display relative line numbers to your cursor position. Really helps with jumping X number of lines.


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.

There are quite a few ways to get around.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: