开发者

Saving a macro in vim with <Esc>

This thread explained saving a vim macro to a file but I cannot get it to work. I have the following macro stored in register b that I am trying to save to my rst.vim file:

let @b = '<Esc>bea**<Esc>`<i**<Esc>gvoo<Esc>e'

Everything inside of '...' came from pasting the macro from the buffer using "bp. But when I close and reopen a rst 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 must be some escape keystrokes I am missing, but I can't find what they are. I tried searching google and :help for similar macro examples with no avail. What am I missing and what terms should I be looking for when searching开发者_开发百科? Thanks!


As hinted at by some, the problem was that <Esc> actually was <,E,s,c,>. Vim generates escapes in a text file using C-v <ESC>. So I ran :s/<Esc>/^[/g on the :let line in the question. Note that ^,[ is not the same as the ^[ generated by C-v <Esc>!

To save myself a headache a few months from now, I switched ^[ to \e. I had to make sure I surrounded the macro in double quotes because single quotes didn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜