52

I'm using 10j to jump down 10 lines, but I want to easily jump 10 lines over and over. I don't want to have to perform the jump with a macro qv10jq@v@@..

I wish there was a method for repeating down keys like motion has f then ; to continually jump (, to go back) to the next character(s).

is there anything shorter than my macro?

tester
  • 22,441
  • 25
  • 88
  • 128

7 Answers7

66

Instead of 10j, you can run:

:+10

Then you can repeat the last ex-mode command with @:.

nelstrom
  • 18,802
  • 13
  • 54
  • 70
  • Another way to repeat the last command is by using `:` followed by arrow-up, enter. Not as fast as `@:`, but you can edit the last command if necessary. – oschoudhury Apr 24 '14 at 10:01
  • 1
    This isn't faster than repeating a macro with `@@` (once you've recorded it and used it). Also, the `@:` method also won't work after you run a different Ex command, such as `:set wrap`. – wisbucky Feb 15 '22 at 08:39
  • This is great, adding `-` takes you backwards for `h`. I wonder if there's anything more we can do like this. Where can we find more information on running line jumps like this directly in command mode? – joeljpa Jul 26 '23 at 11:58
  • Nice to know, but usually, I'm not trying to move down _exactly_ 10 lines, just something in that ballpark. In that case, it seems easier to simply drop down 9 lines and use `9j9j9j...` which is easier than `@:@:@:...` plus setup and allows me to quickly go in reverse with `9k`. This only seems to help if there are specific requirements for precision. If I need to go down more than 10 lines, I probably want to scroll a whole screen with PgDown. I'd like to have a single key that moves down 10-ish lines and doesn't require a remap or (ideally) one-off setup. – ggorlen Aug 24 '23 at 22:15
26

Here's repmo.vim - a plugin to do what you want. It maps ; to repeat the last motion command given with a count.

joeljpa
  • 317
  • 2
  • 13
Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
12

There is no plugin or edit to .vimrc here, but I've found this simple and low tech method works pretty well because it requires no control keys and you can keep both hands stationary while scrolling up or down in any increment of lines or order (e.g. down, down, up):

Let's say you want to move down in increments of 44 lines at a time.

44j   (of course)

Now just leave your left index finger above the "4" key and repeat this to continue scrolling down in increments of 44 lines. Although it's 3 keystrokes, you can do this very quickly as long as you stick to numbers like 22, 33, etc.

Now what is nice about this is that you can quickly reverse direction with no hand movement by just hitting "k" instead of "j", e.g.

44j
44j
44j   (oops, too far, lets go back now...)
44k

Also, you can start with a higher number like 55 (for speed scrolling) and then drop to 22 or 11 to home in on your target. Unfortunately numbers like 77 don't work as well b/c you want to do the number with your left hand, although you could still do higher numbers like 77 with your left hand, it's just that you have strayed from standard touch typing hand position at that point.

JohnE
  • 29,156
  • 8
  • 79
  • 109
11

The solution to this gave me the idea to use noremap to map 10j (or any other number) and 10k to my up and down arrows. I don't know if anyone would be interested in something obscure like this but figured I would comment.

added to .vimrc:

noremap <Up> 5k
noremap <Down> 5j
Keith
  • 113
  • 1
  • 5
4

Try ctrl+f to move a whole page down and ctrl+b to move a whole page back. Not necessarily 10 lines though.

Taken from this site: http://www.thegeekstuff.com/2009/03/8-essential-vim-editor-navigation-fundamentals/

mondaugen
  • 425
  • 5
  • 12
2

I found that mapping 10char jumps to arrow keys work perfectly for navigating. ( ^d, ^u, ^f, & ^b are too big of jumps for my liking). Just paste this into your .vimrc file :)

noremap <Up> 10k
noremap <Down> 10j
noremap <Left> 10h
noremap <Right> 10l

Alternatively, you can map the custom jumps to replacing any of these: ^d, ^u, ^f, & ^b, such as:

map <C-d> 10j
map <C-u> 10k
NoahRay
  • 116
  • 1
  • 3
1

There's a great solution in this answer:.

I found this to have some excellent info:

:help scroll-cursor

The thread also references:

:help motion.txt

You can configure how many lines to move at a time by for example: 15<C-d>

Then subsequent <C-d> or <C-u> strokes will move by the same amount of lines