Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 4 lines.

foo ["bar"]
baz ["k"]
daskhfkjhadsfj ["askfjhfjdsh"]
dfjhafkjhfha ["skkksks"]

I'd like to do a macro that takes the word and yanks it into a register, but I want the register to increment. e.g.:


Is there a way to get this command done in such a way that the registers autoincrement, so I can later paste them:


I'm aware of register numbering and yi" - i'd like to use this with alpha registers instead. I'm also aware that a collision might occur with my chosen register: You can assume that my macro will be recorded in z and I want to use, say, a-f for registers used.

Can you suggest a way to get this accomplished using a macro?

share|improve this question
up vote 2 down vote accepted

With a macro? Maybe. With two macros, sure!

First some setup:

:set nrformats=alpha
:let @y="\"a"

And now some crazy Vim register voodoo:


The strategy is to use one macro (y) to keep track of which register to use next, and modify it using the other macro.

  • f"l@yyf" is from your original, only I've used @y in place of "a. We're using the y macro to type "a instead of typing it directly.
  • GoEsc"yp goes to the end of the file, adds a new line there, and pastes the contents of register y.
  • ^A increments the letter under the cursor. If it was a, now it's b. We set nrformats=alpha earlier so that this would work with letters.
  • 0"yy$ yanks the updated text back into register y.
  • dd^O cleans up our scratch line and jumps back to where we were before, and
  • j0 is the rest of your original.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.