35

How do I cut and paste a column of text in Sublime text 3 -

For example:

File A

Alpha
Beta
Gamma
Delta

File B

AAA
BB
CCCCC

I want to end up with file B having

Alpha AAA
Beta  BB
Gamma CCCCC
Delta
Mike
  • 497
  • 1
  • 4
  • 8

6 Answers6

24

Select and copy the lines on File B you want to copy. Move to File A, select the lines you wish to copy into. Press Ctrl+Shift+L to split your selection into a multiple line selection, move the cursors to wherever you want and paste.

The one limitation of this is that the cursors will keep their relative positions, you may not want this. Perhaps you want them all to remain in a fixed column.

Hold down the middle mouse button and drag to select one or many columns of text, again press Ctrl+Shift+L to split your selection into lines and proceed as before.

owl
  • 414
  • 2
  • 4
17

First, select the lines in File B that you want copied. Note the number X of lines (this should be displayed on the bottom of your screen).

Second, select the first X lines of File A so that there is a cursor at the end. To do this:

  • move your cursor to the end of the first line,
  • go up to the Selection menu, and use the shortcut for Add Next Line until X lines are selected. On OSX, its controlshiftdown.

In this example, there will be 3 cursors at the end of File A that look like this:

Alpha|
Beta|
Gamma|
Delta

Finally, press tab once, then paste your lines. You should have the results you want.

Because of the way this is done, its easier to paste into File A. However, if you really want to paste into file B or some other file, just copy the lines in File A into the target file before you start, and do the same process.

Basj
  • 1,489
  • 7
  • 47
  • 90
LMNOP
  • 322
  • 2
  • 5
  • 1
    I'm accepting your answer as it answers my question as stated. Unfortunately I was really after something a bit more like the column insert available in other editors like Notepadd++ or Visual Studio but it looks like there is no simple way to do this in Sublime. I don't think your solution would work if I wanted to insert the column into the middle of line rather than at the end. Also I got some odd results on windows when I tried extending the line selection down through a ragged set of lines. I didn't have time to investigate this further for now. – Mike Jan 17 '14 at 11:13
  • Was searching for this answer, couldn't make it happen with sublime, atom, visual studio code; however, Visual Studio came to the rescue thanks to your comment!. – oyalhi Jul 05 '17 at 09:07
12

Steps:

  1. Go to File B, and enter multi-selection (++L OR Ctrl+shift+ L) on

    AAA
    BB
    CCCCC
    

    making sure everything is selected, and not just parts of the lines you want to copy.

  2. While in multi-selection mode, copy (+C OR Ctrl+C)

    AAA|
    BB|
    CCCCC|
    
  3. Go to File A, and make sure to enter multi-selection on exactly the same number of lines (in this case 3).

    Alpha|
    Beta|
    Gamma|
    Delta
    
  4. Paste (+V OR Ctrl+V) & voilà :)

Let me know if this works for you!

antoine
  • 143
  • 3
Q8i
  • 221
  • 2
  • 5
2

Little late but found this package on SublimeText forum called Paste as Column. You can find it in Package Control.

Works well, at least enough to get the data in the right area

RE: Original Forum page: https://www.sublimetext.com/forum/viewtopic.php?f=4&t=10008

Tab
  • 121
  • 2
  • way simpler. Works on ST3 and Mac, too. Note: once installed you use it by right clicking at the desired location and choosing `Paste in Column`, right top of dropdown menu. Another item that ST3, for the price, really should include and document out of the box. Couldn't get the CTRL/Command-Shift-L to work, or at least I didn't understand it well enough to. – JL Peyret Apr 11 '18 at 19:22
0

go to file B -> do a multi line select, which on macos can be done by using option and mouse press and drag.

go to file A -> do a multi line select and paste.

What was confusing to me in the previous answers was, how to do the selection in the file B. I was doing a cmd+A, selecting everything.

So the only thing out of the obvious here is you have to do a multi line select in the file B.

anurag
  • 1
0

I found the simple solution in the manual

I just used my middle mouse button (see the manual for other options) to select my insertion point, and then I typed in what i wanted (or pasted it) and it worked.

Vijay
  • 1,120
  • 13
  • 31