1

Let's assume there is a macro stored in register 'r'

I can obtain the contents of this register by executing getreg('r'), but if I print this then it can often be unreadable.

I noticed though that if I execute :registers that the contents of the 'r' register is displayed in a readable format.

Is there a way to do this without calling :registers?

0

1 Answer 1

4

Assuming you want to put the register contents in a buffer use Normal mode command sequence "rp. That'll produce the same thing as you'd see with :reg r.

The thing with getreg() is that it doesn't attempt to output printable characters. For example, if register "r" contains a backspace and you send getreg('r') output to a buffer (e.g. with <C-R>=getreg('r') while in Insert mode) then the backspace will actually move the cursor back. But if you paste the register directly you'll see printable translations of everything. (Example: for me backspace is displayed as <80>kb.)

Note that there is a function that does similar translation to printable characters on whatever you pass to it called strtrans(). Modifying the Insert mode command mentioned above to be <C-R>=strtrans(getreg('r')) will display the same thing as "rp.

2
  • 1
    Sorry for the confusion, but yes you are right, the strtrans function is exactly what I was looking for :) Dec 15, 2019 at 0:01
  • 1
    No worries. It seemed at first like you were looking for "rp but everyone beyond beginner knows that, right? Remembering strtrans(), though, and I was pretty sure I had what you were looking for one way or the other.
    – B Layer
    Dec 15, 2019 at 0:40

Your Answer

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

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