2

Suppose I have an open buffer containing the following text

1111111111
1        1
1 222222 1
1 2    2 1
1 2 33 2 1
1 2 33 2 1
1 2 33 2 1
1 2    2 1
1 222222 1
1        1
1111111111

I can visually select and yank the 2-rectangle with the command 3gg2l<Ctrl-V>8jey

Then, I can immediately reselect and paste the yanked text (not changing the buffer) with gvp.

However, it seems like as soon as I write to the @@ or @" register (even if I don't change the value), something changes, and pasting doesn't work right anymore.

For example, doing

:let @@=@@
:normal! gvp

changes the buffer to

1111111111
1        1
1 222222
2    2
2 33 2
2 33 2
2 33 2
2    2
222222 1
1  1
1  1
1  1
1  1
1  1
1  1
1        1
1111111111

inserting the contents of the register as new lines, rather than overlaying the visual selection.

What am I doing wrong?

5

The problem comes from the register type, you can use echo getregtype('"') before and after your let @@=@@ and you'll see that the type has changed.

:h getregtype() tells us that a register can have different types:

"v" for characterwise text

"V" for linewise text

"{width}" for blockwise-visual text

"" for an empty or unknown register

So when you select your rectangle with ctrl+v and then you yank it, you actually set the type of the " register to visual block (Here ^V6 actually)

When you do let @@=@@ you do no respect the register type. Thus you do not past in block wise mode anymore.

The correct way to set a register is to use the function setreg() which accepts as parameter the register type to set. See :h setreg()

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.