Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

So, 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.

like image 883
Doppelganger Avatar asked Jun 16 '10 15:06

Doppelganger


2 Answers

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.

like image 183
sml Avatar answered Sep 24 '22 03:09

sml


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.

like image 34
Doppelganger Avatar answered Sep 22 '22 03:09

Doppelganger