Alex Rivera | Logout

How do I repeat the last n changes in Vim?

Asked 2011-07-10T22:25:04.197
49

Doing . repeats the last change. Doing 2. repeats the last change two times.

But imagine I want to repeat the change before the last one. How do I do it in Vim?

Edit
Report

1 Answer

10

I wrote the RepeatLast.vim plugin to address this exact requirement. It provides a 5\. key binding to repeat the last 5 changes (including movements) and 2\D to drop/forget the last 2 actions.

It works by enabling macro recording all the time, which may not be desirable for everyone. But if you can live with that, it works in 99% of use cases.

Latest version: https://github.com/joeytwiddle/RepeatLast.vim (Please feedback!)

Caveats:

Please :set ch=2 so that the first line of output won't be hidden by the "recording" message.

The 1% of times it fails to work as intended are usually due to:

  1. Difficulties triggering the CursorHold event slowly without losing fast-repeated keystrokes
  2. Undesirable recording of [Space] and [Enter] keys when the user is responding to a prompt.

Training your q muscle to pre-emptively record macros might be a better approach in the long term. ;-)

answered 2013-05-30T15:38:08.010

Your Answer