Paste multiple lines inside tags as separate line each - Sublime text

Gruber picture Gruber · Oct 9, 2012 · Viewed 19k times · Source

I have to set a list of title/authors item inside an html page, with each title/author line inside a <li> like this:

<ul>
  <li> title name - <em>author name</em></li>
  <li> title name - <em>author name</em></li>
  <li> title name - <em>author name</em></li>
  and so on...
</ul>

They gave me an Excel file with two columns, one for title and one for authors, with about 90-100 rows.

What is the best and quickest way to obtain a list with <li>s like those stated above? (I use Sublime Text 2)

Simply copy/pasting inside Sublime Text 2, i have a separate line for each title/author row, like this

title name author name
title name author name
title name author name

nothing else..

I can easely wrap every single line inside an <li> thx to:

  • menu Selection -> Split into Lines (Cmd/Ctlr + Shift + L)

    and typing the tags, but then i'm stuck to insert, in a sort of automated way, the dash ( - ) after the titles and the <em>s for the authors.

    My best guess is (but I really don't know how to do that) to find a way to copy/paste a bunch of lines and then paste them where every single cursor stand, each as a separate line like this (consider the | as the cursor):
  • *copy* authors name as single lines
    
    |author name1
    |author name2
    |author name3 
    |author name4
    
    *paste* authors as single line each where the cursor "|" stands
    
    <li>title name - <em> |author name1 </em></li>
    <li>title name - <em> |author name2 </em></li>
    <li>title name - <em> |author name3 </em></li>
    <li>title name - <em> |author name4 </em></li>
    

    Unfortunately what actually happens (in sublime text 2) is this:

    <li>title name - <em> |author name1
                           author name2
                           author name3 
                           author name4 </em></li>
    <li>title name - <em> |author name1
                           author name2
                           author name3 
                           author name4 </em></li>
    <li>title name - <em> |author name1
                           author name2
                           author name3 
                           author name4 </em></li>
    <li>title name - <em> |author name1
                           author name2
                           author name3 
                           author name4 </em></li>
    

    all the copied lines simply get pasted in block for every single cursor

    Answer

    Riccardo Marotti picture Riccardo Marotti · Oct 9, 2012

    Probably you only have to verify that the number of lines copied to the clipboard matches the number of lines splitted with CMD+SHIFT+L.

    If they match, Sublime Text behaves as you expected, copying each source line to each destination line (at least on my machine... :).