Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert code in multiple lines in a multiple lines code?

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,
like image 763
G M Avatar asked Nov 24 '13 19:11

G M


People also ask

How do you write on multiple lines at once or code?

You can just Alt + click for additional cursors. And as already mentioned, Ctrl + Alt + ↑ or ↓ . And you can use Alt+Shift+click to select two lines and every line in between.

How do I carry code to next line?

Use Shift+Enter to start a new line after the current line.


2 Answers

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.

like image 156
juanleon Avatar answered Sep 26 '22 06:09

juanleon


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.

like image 36
Ingo Karkat Avatar answered Sep 26 '22 06:09

Ingo Karkat