I'm trying to create a macro for an action that I very frequently use in Python: printing a variable in a bright color so it can easily be found in the traces while debugging.
So lets say there's something like:
myfunctioncall(myvariable)
I want the macro to add:
print("\u001b[35m", myvariable, "\u001b[0m")
on the line below it. (assuming the cursor was anywhere in the word "myvariable")
I tried writing the macro by hand, but I quickly had to realize that I'm still too noobish for that. Instead I recorded the macro, and tried to save that by using the CTRL-R CTRL-R method.
However, it appears for some reason the macro isn't properly "pasted" to my vimrc from the register. The o
-register in code down below is directly recorded to the register. The p
-register is the one that it got from the vimrc (after pasting from register).
c "o yawA^Mprintf(<80>kb<80>kb("\u001b[35m", ^[<80><fd>apA, "\u001b[0m")^[<80><fd>a
c "p yawA^Mprintf(<80>kb<80>kb("\u001b[35m", ^[<80>ýapA, "\u001b[0m")^[<80>ýa
As you can see, it is slightly different. <fd>
has changed into ý
for some reason. Anyone who can explain my why this is and how I can fix it?
(Ps: I know some of you will be tempted to just give me a working macro instead. Those answers are also welcome, but keep in mind that I did not use O
on purpose, but instead used A[ENTER]
so that the Python-indentation is retained.)
EDIT: I just noticed something else that's odd! In the macro snippets above it says printf, while if I use the macro it uses a regular print! This is so odd?
EDIT2: I didn't make it very clear, but the macro in register p
does not work. This is what I get when using it:
printf(<U+0080>kb<U+0080>kb("\u001b[35m",
^[<80><fd>
andý
: vi.stackexchange.com/a/35207/18609 Also, the reason why you seeprintf(
and the macro outputsprint(
is that theprintf(
is followed by two<80>kb
which are backspaces, and then it picks up from the("
part. One thing I didn't understand from your question is whether the second macro"p
actually works or not... Yes, I see they show up differently (I assume that's the output of:reg
correct?) but does"p
actually not work? I'll take another look at the question a bit later, try to reproduce it... Thanks!p
macro doesn't work. It only produces half of what it's supposed to, and also inserts some command characters literally.