Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repeat VIM surround with HTML tag on Visual mode

According to Tim Pope, we can do the following:

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

And you get this

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

I tried and it works. But how can I repeat that command on many other visual blocks? I tried . but didn't work.

Update:

With this text:

foo
foo
foo

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

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

But when I repeat with this @q (with cursor on f letter of second row) it gives this:

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

Instead of

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

What's the right way to do it?

like image 926
pdubois Avatar asked Apr 24 '15 15:04

pdubois


1 Answers

I usually do that with something like:

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

As an alternative, you could record a macro and play it back on each line.

like image 173
romainl Avatar answered Oct 06 '22 01:10

romainl