2

I want to have the following contents in my file

#define BIT_MASK_1      (1 << 0)
#define BIT_MASK_2      (1 << 1)
#define BIT_MASK_3      (1 << 2)
#define BIT_MASK_4      (1 << 3)

so I write one line like this :

#define BIT_MASK_1      (1 << 0)

, and then type Y3p, V3j, so I got four same lines which are selected, and after that I wanted to use the command below to turn the text into the content I want

:'<,'>s/BIT_MASK_/zs/d*/ze//=line(".") - line("'<") + 1
:'<,'>s//zs/d*/ze)$//=line(".")-line("'<")

but I got the E488: Trailing characters error, what did I do wrong?

romainl
  • 186,200
  • 21
  • 280
  • 313
user1726366
  • 2,256
  • 4
  • 15
  • 17

4 Answers4

4

I can't help thinking you're better off using Ctrl+A (increments the number under the cursor) and an interactively defined macro to do this sort of thing.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
3

assume you have the 1st line: (cursor at beginning)

#define BIT_MASK_1      (1 << 0)  

then you type : (^A = Ctrl + A)

qaYp^Af<^Aq

then

3@a
Kent
  • 189,393
  • 32
  • 233
  • 301
1

Not exactly an answer to your question, but I'd rather use C-a to increment the numbers

Something like

t(h^At)^A0

you can put it in a macro and run it as many times as needed

Clément D.
  • 284
  • 2
  • 4
0

Just type this:

:for i in range( 1, 4 ) | call append( line( '$' ), [ '#define BITMASK_' . i . ' (1 << ' . (i - 1) . ')' ] ) | endfor

Sometimes the using of vim as a programing language is better then using weird keystrokes.

bimlas
  • 2,359
  • 1
  • 21
  • 29