8

I'm doing some cut and paste from a lot of different data sources. I'm trying to insert code in multiple lines in a multiple line code so that for the first line of the pasted code go between two specific points of the original code and the same for the second and so on. It's something like insert blocks of code between splitted multiple lines of code. The picture .gif below show what I mean:

enter image description here

How can I do that? I'm trying with VIM CTRL+V but I can't paste multi lines code.

Here is the sample:

VIOLET=SpectralBand([0.380,0.450],'violet')
BLUE=  SpectralBand([0.450,0.495],'b')
GREEN= SpectralBand([0.495,0.570],'g')
YELLOW=SpectralBand([0.570,0.590],'y')
ORANGE=SpectralBand([0.590,0.620],'orange')
RED=   SpectralBand([0.620,0.750],'r')

"viol3et", 45839,
"bl3ue"  , 43903,
"gre3en" , 28392,
"y3ellow", 23049,
"o3range", 12389,
"r3ed"   , 32840,
G M
  • 20,759
  • 10
  • 81
  • 84
  • Perhaps take a look at multiple cursors, which may give you some ideas regarding writing your own custom function for the task at hand: https://github.com/magnars/multiple-cursors.el – lawlist Nov 24 '13 at 19:24

4 Answers4

4

You may use copy-rectangle-as-kill (C-x r M-w) and yank-rectangle (C-x r y) to achieve the behavior you describe.

See the Rectangles section in emacs manual for details.

juanleon
  • 9,220
  • 30
  • 41
4

How Vim behaves during paste is determined by the type of selection during yank. Be sure to select the viol3et block in blockwise visual mode: Ctrl + V (or Q on many Windows installations).

Alternatively, you can use my UnconditionalPaste plugin to just yank / delete the entire lines (e.g. 6dd while on the viol3et line), and then paste (between the target lines) with gbp.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
3

It works for me using CTRL+V, select the whole block with arrows or the movement letters (h, j, k and l), then cut it with d, put cursor after first parentheses of the first line and use p

Birei
  • 35,723
  • 2
  • 77
  • 82
  • 1
    Are you sure, when I go down he selects the next line and when I paste he puts all on the same line... – Johan Nov 24 '13 at 19:18
  • 1
    @Johan: Sure. I had tested it. My version: `VIM - Vi IMproved 7.4` in Linux. – Birei Nov 24 '13 at 19:41
  • @Johan For me it works, how say Ingo be sure to first select with CTRL+V the `viol3et`block and then copy that and not use CTRL+V to insert it... Thanks Birei! – G M Nov 24 '13 at 19:48
2

You should select the top left corner with the cursor, type Control+V, then go to last line, and type $ to get the end of all lines (this was missed in other answers). Then you delete with d, go to the destination, and use p.

For you exact sample, the solution in vim is:

 G0<c-v>{j$dggf(p

Decomposed as:

G     go to last line of file
0     go to its first character
<c-V> to start a blockwise selection
{     go to previous empty line
j     go to next line (hence the beginning of block)
$     extend the blockwise selection to end of ALL lines (that was my point)
d     delete and store the block
gg    go to first line of file
f(    go to next character '(' if on same line.
p     to paste the block after the column of current character.

An alternative to $ is to enable

:set virtualedit=all

and that will do the job if you cannot put the cursor at the destination (when beyond end of its line).

user2987828
  • 1,116
  • 1
  • 10
  • 33