3

I haven't been able to find documentation on how vim knows if register contents came from a linewise-selection vs characterwise or blockwise selection.

For example, given the text below:

Hello there my name is Markus
and I went to the store to buy
bananas and motor oil

If I select the first line in linewise visual mode, yank it to a specific register, and save the register contents to a file, the register contents are only what I had selected:

Nothing special about register contents

Now, if I then reload the unnamed register (@") with the contents of /tmp/output.txt, and paste it, it pastes as if I had selected it in characterwise or blockwise visual mode:

enter image description here

I have to assume that vim is tracking how register contents are set, and that if it is done directly from a yank/cut/delete/etc., it saves which visual mode it was done in.

That being said, how exactly does that work? I'm working on a plugin, and I'd like to be able to tell vim to paste text as if they were originally copied in linewise or characterwise visual mode.

5

You can use getregtype() to get a register's type (characterwise, linewise, blockwise).

echo getregtype('a')

This will yield, v, V, or <c-v> for the "a register.

For more help see:

:h getregtype()
:h getreg()
:h setreg()
  • Fantastic! That's exactly what I was looking for. Also, I forgot about setreg, I'd only been using let @X = "val". Double thanks! – Markus Orreilly Nov 22 '17 at 16:25

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.