You are not logged in.
Hi there!
When pasting a block selection im Vim, the pasted lines are added to the existing lines. That definitely has it's uses, but usually I'd like to paste the lines onto blank lines. For this, I first have to generate a buch of empty lines, and only then can I paste the block. Is there a way to automatically generate new lines when pasting blocks?
Here's a small example in Fortran. I'd like to get the list of REALs by block-selecting the variables and copying them between the REAL and the INTEGER block.
REAL :: &
real1 (2,2) , &
real2 (5,2) , &
real3 (1,2)
INTEGER :: &
int1 ,&
int2
If I just block-select it and paste it onto the line between the REAL and INTEGER blocks, I end up with this:
REAL :: &
real1 (2,2) , &
real2 (5,2) , &
real3 (1,2)
real1
real2INTEGER :: &
real3 int1 ,&
int2
What I'd like to end up with, though, is this:
REAL :: &
real1 (2,2) , &
real2 (5,2) , &
real3 (1,2)
real1
real2
real3
INTEGER :: &
int1 ,&
int2
Without manually inserting blank lines, that is!
PS: I'm not really sure whether that's the correct subforum, but as the questions mostly addresses Programmers/Coders, I guess it should be fine here.
Last edited by cryptkeeper (2013-11-07 08:16:32)
Offline
http://vim.wikia.com/wiki/Unconditional … wise_paste
'\cp' seems to do what you want.
Offline
Karol's answer seems like a more direct solution, but I'd personally go with a combination of simpler commands like "3yy3jPw Ctrl-v 3j$d"
Last edited by Trilby (2013-11-01 11:02:01)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
http://vim.wikia.com/wiki/Unconditional … wise_paste
'\cp' seems to do what you want.
I haven't tried it yet, but it looks exactly what I need! What I do after pasting the selected block is often joining the lines to a single line with the variables delimited by commas or \\|| (for further use in vim regexes), and it looks like this plugin can do exactly this.
Thanks! I'll mark it SOLVED then (and hope I'll get around to actually try it soon enough).
Karol's answer seems like a more direct solution, but I'd personally go with a combination of simpler commands like "3yy3jPw Ctrl-v 3j$d"
The problem with this is that you know the exact number of lines, i.e. 3 in this case, which is usually not the case in the code I work with as the variable lists are much longer.
But what I've become accustomed to in the meantime is memorizing the number of lines that vim shows when I yank the block and inserting that number of new lines before pasting, e.g. for a 24 line block
24o<ESC>j
24k
p
I doubt that using 24o<ESC>j is the best way to insert the 24 blank lines, but it works well enough.
Offline
I doubt that using 24o<ESC>j is the best way to insert the 24 blank lines, but it works well enough.
I used to have a mapping in my ~/.vimrc for '20o<esc>20k' and it worked well enough for me too :-)
Offline
:put
:h :put
:put always works linewise
Offline
It's good to know that vim a builtin linewise paste. Not that I doubted its existence or anything ;P
One day I'll have a go at vimtutor, but I have to finish perpetum mobile first.
Offline
:put
:h :put
:put always works linewise
Awesome, now that's exactly what I'd been looking for! That simplifies things quite a bit.
Thanks!
Offline
Trilby wrote:Karol's answer seems like a more direct solution, but I'd personally go with a combination of simpler commands like "3yy3jPw Ctrl-v 3j$d"
The problem with this is that you know the exact number of lines, i.e. 3 in this case, which is usually not the case in the code I work with as the variable lists are much longer.
But what I've become accustomed to in the meantime is memorizing the number of lines that vim shows when I yank the block and inserting that number of new lines before pasting, e.g. for a 24 line block
24o<ESC>j 24k p
I doubt that using 24o<ESC>j is the best way to insert the 24 blank lines, but it works well enough.
Yank the whole thing in visual line mode (V), which tells you how many lines there are -- then use that number to delete what you don't want in block mode.
"V/real3<Enter>y3jPw<Ctrl-v>3j$d"
Here you don't have to know how many lines there are between the cursor and real3 until after you've done the 'y', which displays the count.
Last edited by Trent (2013-11-07 13:12:59)
Offline
Yank the whole thing in visual line mode (V), which tells you how many lines there are -- then use that number to delete what you don't want in block mode.
"V/real3<Enter>y3jPw<Ctrl-v>3j$d"
Here you don't have to know how many lines there are between the cursor and real3 until after you've done the 'y', which displays the count.
That's actually what I meant by "memorizing the number of lines that vim shows when I yank the block".
Offline
Yes, I understand, but you objected to Trilby's solution because it couldn't count for you, so I wanted to show you that was still possible.
Offline
:put
:h :put
:put always works linewise
Thank you. Only now do I understand what this thread is about. (I always use :put so couldn't see how the problem arose.)
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline