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

前端 未结 7 1454
迷失自我
迷失自我 2020-12-14 07:43

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

I^[A

So I saved it into my .vimrc

7条回答
  •  粉色の甜心
    2020-12-14 08:11

    For a macro:

    :let @e='^[I^[A'
    

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

    See :help c_CTRL-V in Vim for more information.


    For those who've landed on this post looking for how to add ESC to a mapping, the answer is different.

    Literally type <ESC>, thus:

    :nnoremap E IA
    

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

提交回复
热议问题