VIM tag adds to multiple lines with surround.vim

I have these three (or more) lines that I want to surround with li (or any other) tags:

Bananas
Citrus
Orange

I can do it this way: qaysstli>jq then 2@a .

Is there a way to do this faster and without a macro?

+4
source share
4 answers
  • Visually select all rows using <Sv>
  • Type :norm yss<li> , then <CR>

Result:

 <li>Bananas</li> <li>Citrus</li> <li>Orange</li> 

Ranges are also good:: :.,+2norm yss<li><CR> does the same as :1,3norm yss<li><CR> .

+17
source

Use Visual Block and then surround.

<cv> to start the visual block mode, and then go to the last line of text. Use $ to select the end of each line, then S<li>

Together:

 <cv>2j$S<li> 
+5
source

The faster I think about it using zencoding-vim . With this plugin, you can visually display text, then type ctr + y , and type:

 ul > li* 

Adn you get a list. It is like magic, and it is very fast.

+4
source

Not the most efficient way, but found it useful as a beginner, you can use Visual Block twice to add a tag at the beginning and end of a word.

  • <cv> to start the visual block, and then use I to insert the first <li> ending with [esc] .
  • <cv> to start the visual block, and then use $ to select the end of the block. Use A and then add <li> , end with [esc] .

All together: <cv>2jI<li>[esc] and <cv>2j$A<li>[esc]

0
source

Source: https://habr.com/ru/post/1393639/


All Articles