views:

38

answers:

2

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.

+2  A: 

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.

scomar
You're right, I had spaces between the ^M, and that's why it failed for me.
Doppelganger
You can use double quotes and `\<C-m>` inside them if you do not want to have binary data inside your vimrc.
ZyX
+1  A: 

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.

Doppelganger