3

Suppose I have this file open in Vim:

AXXK  M(X)
1.1   1
1.2   8

And that the clipboard holds

U(1X)
MX1
MX2

How can I easily paste that content as a new column? I want:

AXXK  M(X)  U(1X)
1.1   1     MX1
1.2   8     MX2

I have a strong feeling I could do it very easily in the past, so maybe there is an option to enable it?

I have tried simply pasting with the cursor on the ) character, but I get

AXXK  M(X)
U(1X)
MX1
MX2
1.1   1
1.2   8

Also the same result with :set virtualedit=all.

PS: The number of spaces of separation between the columns does not matter, I can filter it through column -t to get a pretty format if needed.

1 Answer 1

4

The problem is the clipboard. For its internal registers, Vim keeps track of what type they are (characterwise, linewise or blockwise). See also :h getregtype().

However for the clipboard, Vim cannot know, because any program could have put data in there, so it will always assume linewise. You can however force a different way, just call setreg() like this:

call setreg('+', @+, 'b')

This set's the content of the clipboard (the + register) to itself but changes the type to blockwise (the b).

If you need this more often, you can make use of Ingo Karkats UnconditionalPaste plugin, that would let you paste using e.g. +gbp (if I am not mistaken).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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