3

I just started with Vim recently and I got stuck with a basic problem!

When I want to copy and paste more than one line of my codes and paste it in the other place, the original codes will not move down after I paste my lines on top of them. For example, my original codes is look like:

aaa
bbb
ccc

after I using visual mode to select all of them and using 'y' to copy, then I move my cursor to the top-left of my file and use "P" to paste them on the top of my file, it becomes:

aaa aaa
bbb bbb
ccc ccc

instead of what I want

aaa
bbb
ccc
aaa
bbb
ccc

I don't know what I just got wrong? or is this the way how vim deal with copy and paste? so I need to push the original lines down first before I paste them on it? it's sounds a little inconvenient to do so!

Can anyone tell me how to do what I want easily? Thanks!

1
  • 1
    It sounds like you are using Visual-Block mode (Ctrl-v), try selecting the lines with Visual-Line mode instead (Shift-v)
    – Thor
    Mar 25, 2015 at 14:15

1 Answer 1

4

It looks like the register contents you've yanked originate from a blockwise selection. Then, on paste, Vim will indeed insert the contents inline, making space for the amount of text in the register, instead of inserting brand new lines.

You should use the V command for linewise visual selection. Then, the correct expected paste behavior will happen on paste automatically.

Note that my UnconditionalPaste plugin offers paste mappings that force a certain mode. So, with its glp mapping, you could force linewise pasting from a blockwise selection. But it's better to do the "right" selection in the first place.

2
  • What is the difference between Shift-v and just v? Both appear to behave the same way, except v highlights each line as you move through the file.
    – sherrellbc
    Aug 1, 2017 at 7:58
  • 1
    @sherrellbc v allows to select incomplete lines, e.g. single words Shift-v always selects complete lines. Aug 1, 2017 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .