Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a Vim macro that contains "Escape" key presses?

Tags:

vim

macros

I use the following Vim macro a lot (it puts the current line inside XML 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 in .vimrc

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

like image 899
Nicolas Raoul Avatar asked May 31 '10 12:05

Nicolas Raoul


People also ask

What happens if you press the Escape key while a macro is being recorded?

Escape key adds extra bytes into the register when recording a macro.

How do I record a macro in Vim?

To record a macro and save it to a register, type the key q followed by a letter from a to z that represents the register to save the macro, followed by all commands you want to record, and then type the key q again to stop the recording.

How do I get out of Vim without the escape key?

If you use Vim in a terminal, simply press alt/meta+normal_mode_key. Most terminals send an escape character followed by the normal_mode_key that you pressed, removing the need to press escape yourself.

Do Vim macros persist?

6) actually persists macros and named buffers automatically (by default, although I haven't looked for a way of turning this behavior off). Closing a Vim session will update the ~/. viminfo file with any named buffers / macros.


1 Answers

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

like image 72
catchmeifyoutry Avatar answered Sep 23 '22 09:09

catchmeifyoutry