Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

  • like image 707
    Gruber Avatar asked Oct 09 '12 18:10

    Gruber


    People also ask

    How do you copy multiple lines in Sublime Text?

    You can duplicate selected text blocks with Ctrl+Shift+D several times. Select some text and press Ctrl+D several times to select more occurrences of the selected text. This spawns a cursor on each selected text which can be moved via cursor keys.

    How do you separate text in Sublime Text?

    Split Line Sublime Plugin Using ctrl+shift+\ ( ctrl+shift+` for OSX) or the context menu option split a single-line array into multiple lines.

    How do I copy and paste in Sublime Text?

    To do that -> simply press ctrl + c with the cursor anywhere on the line you wish to copy(no text-selection please) and hit ctrl + v with the cursor anywhere on the target line. The copied line will get pasted right above your target line.


    2 Answers

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

    like image 139
    Riccardo Marotti Avatar answered Sep 16 '22 11:09

    Riccardo Marotti


    I actually just found the answer to this, and wanted to share just in case anyone else encounters this. Riccardo is right but I can expand.

    Sublime will paste in chunks when you expect to paste in place when there is not a match between the number of sources and targets. I've encountered your bug when there's an extra hard return or extra element. So for example.

    |author name1 |author name2 

    Will trigger Sublime to paste the two values into place because there are two source values and one target element.

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

    So to Riccard's point, you likely might have had selected a little extra that Sublime recognized as a extra value.

    So to fix this, you'll need to have equal sources and targets.

    |author name1 |author name2  <li>title name - <em> |author name1 </em></li> <li>title name - <em> |author name2 </em></li> 
    like image 37
    Pat DePuydt Avatar answered Sep 20 '22 11:09

    Pat DePuydt