Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to surround multiple lines individually with surround.vim

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 ?

like image 993
woodspock Avatar asked Jan 29 '12 19:01

woodspock


2 Answers

  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>.

like image 182
romainl Avatar answered Sep 22 '22 00:09

romainl


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>
like image 45
Peter Rincker Avatar answered Sep 18 '22 00:09

Peter Rincker