Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A more powerful version of dot (repeat)

Tags:

vim

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.

like image 785
Steven Lu Avatar asked May 23 '13 19:05

Steven Lu


1 Answers

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 @@.

like image 70
Jay Avatar answered Sep 29 '22 20:09

Jay