0

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

RxMsgType0
RxMsgType1
RxMsgType2
RxMsgType3
...

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]

RxMsgType4
RxMsgType5
RxMsgType6
RxMsgType7

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.

statox
  • 49,782
  • 19
  • 148
  • 225
HarshaD
  • 111
  • 2
  • @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 Jul 23 '19 at 20:51
  • 2
    Code review: have you considered using an array instead? – D. Ben Knoble Jul 23 '19 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 Jul 23 '19 at 23:18
  • 1
    @D.BenKnoble Interestingly enough, that would probably only change the current question from RxMsgType4 to RxMsgType[4] :-P – ChatterOne Jul 24 '19 at 09:10

1 Answers1

2

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

  • paste the variable n times
RxMsgType0
RxMsgType0
RxMsgType0
RxMsgType0

... n times

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