In my C code I am dealing with many variables of type


My Question: Is there a way in VIM by which I can create 4 more variables which follow the same format?

Expected output: [Type Some Command]


In the future I would like to pass the

name (RxMsgType assumed here ) 

number( we assumed 4 here) 

as an argument to get the variable names formed.

That is my final aim.

  • Related post: Yanking and pasting while incrementing Commented Jul 23, 2019 at 19:39
  • @PeterRincker's link is probably what you want. And to make it persistent, you could dedicate a register to it, e.g i and so put in your vimrc : let @i='yyp^A' where ^A is the actual CTRL-A character that you can insert with <c-v><c-a>. Than you can do [count]@i. Note that this increases the first number on the line. If you have a more complex line, add a line-motion between yyp and ^A to place your cursor in the right spot. Also consider looking :help nrformats
    – perelo
    Commented Jul 23, 2019 at 20:51
  • 2
    Code review: have you considered using an array instead?
    – D. Ben Knoble
    Commented Jul 23, 2019 at 21:15
  • @perelo let @i = "yyp\<C-A>", using double quotes allow using \<...> to refer to keystrokes by name, so no need to insert a special character in vimrc for that. Using a mapping is also possible (though I actually quite like the idea of the dedicated register!)
    – filbranden
    Commented Jul 23, 2019 at 23:18
  • 1
    @D.BenKnoble Interestingly enough, that would probably only change the current question from RxMsgType4 to RxMsgType[4] :-P
    – ChatterOne
    Commented Jul 24, 2019 at 9:10

1 Answer 1


An alternative solution if you are using vim 8 using the g<c-A> command:

  • paste the variable n times

... n times

  • select all line wise e.g if that's the whole file gg <s-V> G
  • use g <c-A>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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