tags:

views:

170

answers:

4

I use the following Vim macro a lot (it puts the current line inside tags):

I<e>^[A</e>

So I saved it into my .vimrc

let @e='I<e>^[A</e>'

But it does not work.
The ^[ part means Escape but it is not understood as such when using .vimrc

How can I save this macro, or any macro that contains "Escape" ?

+4  A: 

Try entering the escape with <Ctrl-v><Esc> in insert mode. See :help i_CTRL-V in vim.

catchmeifyoutry
No it shouldn't. With <ctrl-V><esc> the ^[ is a single charater (escaped code for ESC), not the '^' and '[' characters. Just tested it again in vim and gvim 7.2, it correctly wraps a line in tags.
catchmeifyoutry
simple test, when you move the cursor along the ^[ part, you shouldn't be able to place it between the ^ and [, as it represents a single keycode.
catchmeifyoutry
The trick was indeed this single keycode character, I didn't see difference at first. Thanks a lot!
Nicolas Raoul
np, good luck :)
catchmeifyoutry
+2  A: 

<ESC> is your friend here. Literally type <ESC>, thus :

let @e=I<e><ESC>A</e>

See :help key-notation in Vim for more info.

Update:

Ah... <ESC> works in key mappings (such as :map <Leader>e <ESC>I<e><ESC>A</e> [tested]) but not in macros, which are expanded literally. I have just tried and tested this:

:let @e='^[I<e>^[A</e>'

Where ^[ is just one char formed by hitting CTRL+VESC. Note the escape right at the beginning of the macro.

Johnsyweb
<ESC> does not work. Besides, I think quotes are needed.
Nicolas Raoul
Now I think I understand what you mean by "does not work". Answer updated.
Johnsyweb
It works, thanks a lot :-D The trick was to use this single character instead of ^[ Now I realize catchmeifyoutry had the solution!
Nicolas Raoul
Glad you got it working. You may find that `map`-pings are more useful if you have a lot of such shortcuts as they do not trample on your `registers`.
Johnsyweb
Indeed, mappings seems to be more appropriate for my usage, thanks again :-)
Nicolas Raoul
No problems. Happy to help.
Johnsyweb
+1  A: 

If you're using Windows behavior for vim where Ctrl+V is the Paste command, the equivalent sequence is Ctrl+Q

Nick Canzoneri
+1  A: 

Today I discovered a vim plug-in called MARVIM (http://www.vim.org/scripts/script.php?script_id=2154).

It is capable of storing macros and executing them later using shortcuts.

Oz