Sometimes I'll guess a count for a cursor movement, say 4b but it was actually 7 words away. If I'd performed an edit I could press . to repeat; I could have done @: to repeat a command line.

It would be useful to repeat 4b again. This functionality would also be useful, saving more keypresses, if, having done 10<C-w>> I could repeat the window resize with a single key.

Is there a way of doing this I've overlooked?

  • 3
    stackoverflow.com/questions/26553239/vim-repeat-previous-motion There are multiple Plugins to repeat motions. But actually you might want to have a look at easy-motion github.com/easymotion/vim-easymotion which solves your problem in a different way. But i don't think one of this will be suitable for window resizing, but there are different plugins for that ;-) – Doktor OSwaldo Mar 8 '17 at 10:27
  • @DoktorOSwaldo Thanks. I've that plugin previously (not for this reason) but found it very intrusive. I also struggled to configure it; I think I found the docs confusing when trying to discover how to change its leader key (it keeps talking about previous behaviour which I'm not interested in). I try to use as few plugins as possible. At least you're confirming I've not missed any built-in support for what I'm after. – user859 Mar 8 '17 at 11:03
  • 1
    I would also love an answer for this, but I think we'd use it as a crutch. We're not looking for 8 words back, we're looking with the second F or something. I think the reason vim doesn't support this is because there's better ways to accurately get there. – TankorSmash Mar 9 '17 at 16:14
  • @TankorSmash There might be better ways of achieving particular examples but having a general solution would clearly be a massive improvement as you'd only have to learn one keypress. Consider repeating zL or zH for example (to page left and right through long lines). I don't want to do 4zL, for example - I want to go through the text one page at a time. Or 24j to go down exactly that many lines (so that when you're navigating a document which has lots of 24 line blocks of text with a few deltas those deltas are more obvious). etc. – user859 Mar 10 '17 at 10:25
  • Of course there's always macros that can repeat whatever and however many key presses you like. When you get passed simpler things that are easy for Vim to guess macros are your friend. – Tumbler41 Apr 7 '17 at 13:31

Since you mentioned cursor movement but not ; there is of course

;     Repeat latest f, t, F or T [count] times.
,     Repeat latest f, t, F or T in opposite direction [count] times. 

This is very helpful to get to the next occurrence of the character you just searched for.

IMHO I'm don't think repeating 4b would be worth it.

  • 1
    I know about those; it's the actions which don't have repeats I'm looking for. And I'm not sure I agree that pressing a key to repeat 4b is not worth it yet typing ; to repeat fa is a big saving over pressing fa again. – user859 Mar 8 '17 at 13:11

As the comments to your post indicate, the best solution to this question is usually to find a different approach, like vim-easymotion*.

However, on the general topic of repeating a normal mode command:

You can execute the command with :norm[al] and then use @: to repeat the last command line.

For example :norm 4b and then @: to keep jumping backwards. If @: is hard to type on your keyboard, you can remap it to make it more practical:

nnoremap <leader>. @:

(Using <leader>. may not be a good idea, I haven't tried that particular combination myself.)

Note that for "special" characters (Ctrl+F, PageUp, Enter, etc.) :normal does not accept keycodes (e.g. <C-F>, <PageUp>, <Return>) so the actual key presses must be inserted which is done by preceding them with Ctrl-V. But there is a way to use keycodes as described by :help normal:

An alternative is to use :execute, which uses an expression as argument. This allows the use of printable characters to represent special characters. Example: :exe "normal \<c-w>\<c-w>"

* Why vim-easymotion is called that and not vim-kriskross will forever remain a mystery to me. After all, it lets you "jump-jump".

  • Actually when using @: you use a macro from the : register. Since you used a macro, you can repeat your macro with @@. Which is a lot easier to type. So :norm 4b then @: and then @@ until you're happy. – Hielke Walinga Sep 21 '18 at 13:28

Your Answer

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