Saving a macro in vim with <Esc>
This thread has explained saving the vim macro to a file, but I cannot get it to work. I have the following macro saved in register b, which I am trying to save in the rst.vim file:
let @b = '<Esc>bea**<Esc>`<i**<Esc>gvoo<Esc>e' Everything inside "..." came from inserting a macro from the buffer using "bp . But when I close and The quick brown fox jumped over the moon first file containing only the sentence The quick brown fox jumped over the moon and type fbv2e@b , this is the resulting sentence:
Thc>bea**<Esc>`<i**<Esc>gvoo<Esc>e quick brown fox jumped over the moon. So there should be some escape keys that I am missing, but I can not find what they are. I tried google search and :help for similar macros, to no avail. What am I missing and what conditions should I look for when searching? Thanks!
As someone hinted, the problem was that <Esc> was actually < , E , s , c , > . Vim generates escape files in a text file using Cv <ESC> . So I ran :s/<Esc>/^[/g in the line :let in the question. Note that ^ , [ does not match ^[ generated by Cv <ESC> !
To save myself a headache after a few months, I switched ^[ to \e . I had to make sure I was surrounded by double quotes in the macro, because single quotes do not work.