开发者

How do I save a macro consisting of multiple search and replace into my .vimrc

开发者 https://www.devze.com 2023-01-03 12:24 出处:网络
I have a macro that I use to replace special characters for its html entities. I would like to save it in 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/á/\&aacute;/g^M:%s/é/\&eacute;/g^M:%s/í/\&iacute;/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:á:\&aacute;:Ige^M:%s:é:\&eacute;:Ige^M:%s:í:\&iacute;:Ige^M'

Don't forget the last ^M, and that a vim restart is needed in order to reload the .vimrc.

0

精彩评论

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