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

21,665

Solution 1

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

Solution 2

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>
Share:
21,665

Related videos on Youtube

Gruber
Author by

Gruber

Updated on July 04, 2021

Comments

  • Gruber
    Gruber almost 3 years

    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

  • Gruber
    Gruber over 11 years
    agh dammit so simple! i wasn't watching for that, thx a lot really!
  • Database
    Database over 11 years
    Thanks for the answer. For those struggling like I was, if the number of lines don't match, you'll find it pastes n copies, where n is the number of lines selected. So if you have 10 lines selected, and 11 lines in the clipboard, you end up with 10 x 11 = 110 lines. Moral of the story: make sure they match.
  • tnrich
    tnrich over 8 years
    If the 1:1 paste isn't working because you're copying multiline selections, try using 'Command+J ' to join the selection onto 1 line before copying
  • risyasin
    risyasin over 7 years
    I really needed to say "thank you", this answer & ST3 is just life saver.
  • starmandeluxe
    starmandeluxe almost 3 years
    WOW, I couldn't for the life of me figure out why it was pasting all into the first line. It was because the number of lines didn't match! This helped me fix it, thank you!
  • codemonkey
    codemonkey over 2 years
    This behavior was troublesome for me, I want to achieve to copy all content to each line, but coincidentally it matched with the number of rows! I could only understand after reading this answer.
  • fortuneRice
    fortuneRice about 2 years
    If it looks like number of lines copied to clipboard (e.g. n excel rows) matches the number of line splits (e.g. n line splits) but it still doesn't work, try adding an extra line in your sublime file.