How do I save a macro consisting of multiple search and replace into my .vimrc
I have a macro that I use to replace special characters for its html entities. I would like to save it in my .vimrc.
According to this, I should use let @r=' macro_text_goes_here '. The problem is that my macro is a series of search and replace, something like this:
:%s:á:\á:Ige
:%s:é:\é:Ige
:%s:í:\í:Ige
S开发者_如何学JAVAo, I've tried with ^V-enter, <enter>, <CR> using real line breaks, but it never works. On the other side, if I put the text on a register and then run the macro, it works as expected.
adding this to .vimrc works for me
let @a=':%s/á/\á/g^M:%s/é/\é/g^M:%s/í/\í/g^M'
note that ^M is a special character entered using Ctrl+V, Ctrl+M.
Ok I found the solution, I had tried with ^M before, but having some trailing spaces it didn't work, the proper syntax for the example on the question is:
let @r=':%s:á:\á:Ige^M:%s:é:\é:Ige^M:%s:í:\í:Ige^M'
Don't forget the last ^M, and that a vim restart is needed in order to reload the .vimrc.
精彩评论