8

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

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 ?

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
woodspock
  • 93
  • 1
  • 5

4 Answers4

25
  1. Select visually all the lines with <S-v>
  2. Type :norm yss<li> then <CR>

Result:

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

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

romainl
  • 186,200
  • 21
  • 280
  • 313
10

Use Visual Block and then surround.

<c-v> to start visual block mode and then move to the last line of the text. Use $ to select to the end of each line then S<li>

All together:

<c-v>2j$S<li>
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
5

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

ul > li*

Adn you'll get the list. It looks like magic and it's very fast too.

lucapette
  • 20,564
  • 6
  • 65
  • 59
  • Exactly what I needed! I was pretty sure it was also possible with zencoding but didnt know how too. Thanks ! – woodspock Jan 29 '12 at 20:21
  • More than welcome. Please accept it if it solved your problem ;) – lucapette Jan 29 '12 at 20:36
  • I accepted the other answer cause it's better related to the title of my question, but I'll probably use your answer more often when coding ;-) – woodspock Jan 29 '12 at 21:10
1

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

  1. <c-v> to start the visual block and then use I to insert the first <li>, end with [esc].
  2. <c-v> to start the visual block and then use $ to select to the end of the block. Use A and then append <li>, end with [esc].

All together: <c-v>2jI<li>[esc] and <c-v>2j$A<li>[esc]

gaboroncancio
  • 870
  • 1
  • 7
  • 19