7

I'm not really sure how to describe what I'd like to do. Basically I'd like to use visual block mode to select a region of text and then paste it "as a collection of lines" rather than as a rectangle.

a b
c d
e f
g h

after pressing gg0<c-v>Gy the rectangle a/c/e/g is in the default yank register (I forgot what it's called).

If I then paste the rectangle p I get the following:

aa b
cc d
ee f
gg h

I'm wondering if it's possible to paste a rectangle / visual block selection on a group of lines by itself, as if it were an ordinary visual selection.

a
c
e
g
a b
c d
e f
g h
  • You can set register type to linewise before pasting. Something like this: :call setreg('+', @+, 'V'). Depending on your OS and your setting of clipboard, you might need to do this for registers * or " instead. It's longer to type than the answer below, but it might still come in handy in more complicated contexts. – lcd047 Jul 21 '16 at 17:52
11

Try this:

:put! "
  • :put: insert the contents of the specified register
  • !: insert before the current line (the default is after)
  • ": the unnamed register (check :help registers for details)

You could do it from insert mode as well: Ctrl-r+"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.