Sublime Forum

Paste As Block

#1

I really like Sublime Text 2 but there is one feature that I wish it had. I use Textpad which allows you to paste a block of text with a document. Using Text pad, you find the point of insertion and right click, choose insert, paste as block.

Example:

abcd123
efghi456
jklmn789

It would be nice if I could right click between the d and the 1 and paste a block of text so it would look like this:

abcd00a123
efgh00a456
ijkl00a789

0 Likes

#2

I made a very simple plugin that does exactly that : it’s in package control under the name “Paste as Column” (default shortcut is ctrl+alt+v).
Repo is bitbucket.org/Clams/sublimepastecolumn in case you need to install it manually.

Note that sublimeText already handle this kind of stuff but not in the exact way you are describing: if you do copy a block of text of n line and then put exactly n cursor the default paste function will insert each line where are each cursor. The behavior is slightly different, and in the end I use both :stuck_out_tongue:

0 Likes

#3

I’m unsure how to use your plugin, Clams.

Three lines:

[quote]abcd123
efghi456
jklmn789[/quote]

I want to paste 00a after the first d in the first line for all three lines (I take the example of the first post).
After placing the cursor and hitting ctrl+alt+v only the first line is modified. Line 2 and 3 are untouched.

Your plugin get’s executed:
key evt: control+alt+v
command: paste_column
Modifying line 0 at col 4 ##abcd123##–00a-- with start=0 end=7 prev=-1

Did I do anything wrong?

0 Likes

#4

Until ST2 gain the possibility to read your mind, you have to tell it how many lines you want to paste.
So for your example, your clipboard must contains 3 lines:

00a 00a 00a
Or as Clams explained, you must create 3 cursors and use the default paste with 1 or 3 lines in your clipboard (you know how multi-selection work in ST2, right ?)

0 Likes

#5

The plugin recopy a block of text (multiple line) and insert it wherever you want.
If your block is only one line, then it just behave like a simple paste.

Maybe a better exemple would be:

abcd0123
efgh1456
jklm2789

imagine that you copy somewhere the following block

00a0
00a1
00a2

if you place the cursor after the d and hit ctrl+alt+v you would get
abcd00a0123
efgh00a1456
jklm00a2789

And the other where I think it start to be really useful is when you try to do that let’s say 4 character after the 0123: you insert space in the first line to put your cursor there, and then it ctrl+alt+v and you get

abcd123 0a01
efgh456 00a1
jklm789 00a2

with the space at the end of other line inserted, something that you cannot do easily with ST2 since you cant put cursor after the end of the line.

If you simply want to repeat on multiple line the same text then you can simply use the multiselection from ST2, then paste and it works fine without any plugin.

Edit: bah, I’m too slow, Bizoo explained itperfectly :stuck_out_tongue:

0 Likes

#6

That’s what I was waiting for^^ :smile:

Thanks for the explanations, got it now…

0 Likes

#7

[quote=“Clams”]I made a very simple plugin that does exactly that : it’s in package control under the name “Paste as Column” (default shortcut is ctrl+alt+v).
Repo is bitbucket.org/Clams/sublimepastecolumn in case you need to install it manually.

Note that sublimeText already handle this kind of stuff but not in the exact way you are describing: if you do copy a block of text of n line and then put exactly n cursor the default paste function will insert each line where are each cursor. The behavior is slightly different, and in the end I use both :stuck_out_tongue:[/quote]

THANK YOU VERY MUCH! This package worked perfectly for what I was needing to do…it let me paste over 300 rows with ease…huge time saver. Thanks again.

0 Likes

#8

Simple way to do this.

  1. Select the text to paste as a block (On Mac: Option + Drag mouse)
  2. Select the part where you want to paste as a block (if beginning of line, just drag a vertical line)
  3. Paste

A little long, but works well

0 Likes

#9

I am in heaven!!! As a forever SlickEdit user now moving to Sublime, the lack of block pasting was the only problem for me —

Thank you.

0 Likes

#10

I’ve been using this plugin and I think it’s great.

One question:

Is there a way it could be modified to paste in overwrite mode instead of insert mode?
(I’ve tried changing to overwrite mode before pasting but it doesn’t change behavior)

It would be useful for replacing columns of data (especially if each row being replaced is not the same length.

Thanks.

0 Likes

#11

I just pushed an update: you just need to an the argument “mode”:“overwrite” to the shortcut you are using and it should work (i tested very quickly, tell me if you see some strange behavior).
To bind it to ctrl+alt+shift+v you can put the following line in your sublime-keymap file :

{ “keys”: [“ctrl+alt+shift+v”], “command”: “paste_column”, “args”: {“mode”: “overwrite”} },

0 Likes