2

In vim I often find myself j-stepping by line to go, say, 8 or 10 lines down. For example, if I have a directory open in netrw and the directory I want is 8 lines down I will just jjjjjjjj+ENTERENTER. If it is farther down than that I will use a / search.

Is there any more efficient way for me to do this kind of navigation? I guess I could use 8j but the problem there is that you don't know the exact number of lines so you end up j-ing and k-ing anyway. My feeling is there is probably some trick that is better than spamming j.

5
:set relativenumber

has been created to solve that problem.

  • Wow, that is VERY useful! – Wildcard Sep 27 '15 at 17:11
1

What I find useful is instead of moving the cursor around I move the screen:

Ctrl-e - Scroll the screen upwards
Ctrl-y - Scroll the screen downwards

As this scrolls the screen then I can easily read the code rather than paginating and then working out where I was.

Then I move the cursor to where I want it on the screen:

H   move to top of the screen
M   move to middle of the screen
L   move to bottom of the screen
  • I have not tried Ctrl-e before. I do use z. a lot. – Tyler Durden Oct 21 '14 at 15:46
  • 1
    I think of H/M/L as High/Middle/Low. – Jim Davis Oct 21 '14 at 18:21
1

My personal solution to this is to do 5j or 5k commands to move 5 lines up or down. I find that it's faster to do repeated 5j commands, which have become part of my muscle memory, than it is to try to calculate an exact jump.

Of course conditions exist when you want an exact jump, but if you're editing text or code, doing a few 5j commands followed by individual j or k commands gets you there pretty fast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.