8

I know about recording with q into registers, but I was wondering if it's possible to set something up to quickly recall the last recording, in much the same way that . recalls the last short editing command (see here for a discussion on .).

I know about @@ but it only seems to work after doing @z where z is the register used. e.g. to make the recording you must type qz, go on to do your thing, q, and then in order to run the recording you must @z before you can start @@-ing to repeat that.

My hack solution now is a bind nnoremap , @q which lets me do recordings with qq and ending them with q. Is there something better (e.g. something that records into a particular register with a single keystroke, or something that specifically repeats the last-recorded macro)? admittedly that isn't a huge improvement, as it's pretty optimal already.

For me a single register that is easy to use is generally more useful than a large number of registers that require a bit more work to get at. Though this could just be that I'm bad at remembering things and don't see myself effectively making use of more than one.

Community
  • 1
  • 1
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • @@ works for any macro in my vim. So ... painful as it may be, what vim and what platform are you on? – Ram Rajamony May 23 '13 at 19:54
  • 2
    @RamRajamony I think the question is about executing the last recorded macro as opposed to the last invoked macro. – Don Cruickshank May 23 '13 at 20:03
  • If you mostly use just one register for macros I actually think your solution is pretty good. I map Q to @j myself, and qj is easy to press! – Daan Bakker May 23 '13 at 21:05

2 Answers2

2

Since you like to use the same register for all your macros and just record over it as needed, you can set and execute that register in your _vimrc file so that @@ is "primed".

In your _vimrc file, add:

let @z = ''
execute 'normal @z'

Now, as soon as you record a macro in register z, you can immediately execute it with @@.

Jay
  • 56,361
  • 10
  • 99
  • 123
  • Interesting though this feels like a set-up for strange behavior in the future. What'd be nice is if there is just something that tracks the last macro. – Steven Lu May 23 '13 at 21:34
0

You could try some plugins that do something similar to what you asked:

RepeatLast.vim and record-repeat.vim

Another option could be use some function and associate it with repeat.vim.

mMontu
  • 8,983
  • 4
  • 38
  • 53
  • repeat.vim might be promising. It's clearly not worth it to pursue this though. Those other options feel inferior to my existing no-plugin-needed binding. – Steven Lu May 25 '13 at 02:57