How to repeat VIM environment with HTML tag in Visual mode

According to Tim Pope , we can do the following:

Finally, let try out visual mode. Press a capital V (for linewise visual mode) followed by S<p class="important">. 

And you get it

 <p class="important"> <em>Hello</em> world! </p> 

I tried and it works. But how can I repeat this command on many other visual blocks? I have tried . but did not work.

Update:

With this text:

 foo foo foo 

I tried this qqgvS<p class="important">q . He gives correctly

 <p class="important"> foo </p> foo foo 

But when I repeat @q with this (with the cursor on the letter of the second line), it gives the following:

 <p> <p class="important"> foo </p> </p> foo foo 

Instead

 <p class="important"> foo </p> <p class="important"> foo </p> foo 

What is the right way to do this?

+5
source share
2 answers

You can not; the repeat.vim plugin only handles repetition from normal mode. I wrote a companion visualrepeat plugin , but surround.vim does not support this.

For built-in commands, you can make a visual selection via gv:normal .<CR> , but this does not work here.

The only option I see is to record a macro and then execute this for each previous selection (using gv ).

+3
source

I usually do this with something like:

 :'<,'>norm! yss<p> 

Alternatively, you can record a macro and play it on each line.

+3
source

All Articles