创建宏时 VIM 映射无法正常工作

标签 vim mapping vim-macros

我大约 3 天前开始学习 VIM。现在我无法创建宏。

在开始学习 VIM 时,为了方便起见,我创建了映射:jk -> ESC (inoremap jk <ESC>)。现在我的宏只有在我按下 ESC 时才能正常工作;使用 jk 它们无法正常工作。

例如,我创建宏来添加 :行首和行尾:

'I' + ':' + 'ESC' + 'A' + ':' + 'ESC'

@a macros: 我用 jk 退出了插入模式.
@b macros: 我用 <ESC> 退出了插入模式.

如果申请@a转到 example 行,我最后得到冒号...我 结束于:

:example

如果申请@b转到 example 行,我确实在最后得到了冒号...我结束了 与:

:example:

命令输出 - :registers (宏不一样): enter image description here

~/.vimrc :

1 syntax on " highlight syntax 
2 set number " show line numbers
3 set hlsearch " highlight all results
4 set noswapfile " disable the swapfile
5 set ignorecase " ignore case in search
6 set incsearch " show search results as you type
7 " set spell spelllang=en_us " misspelled words are automatically underlined
8 
9 inoremap jk <ESC> " type 'jk' for leaving insert mode

问:如何在录制宏时使'jk'和'ESC'的行为相等。

附言 很抱歉,如果解释不顺畅,这是我的第一个问题,我尽量让它尽可能简单。

最佳答案

您需要将评论上移。

代替:

inoremap jk <ESC> " type 'jk' for leaving insert mode

做:

" type 'jk' for leaving insert mode
inoremap jk <ESC>

Vim 将此注释解释为映射的一部分。

有关更多信息,请参阅“Why does remapping make the cursor jump?”。

关于创建宏时 VIM 映射无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70905005/

相关文章:

vim - 在 Vim 中如何在同名的 .h 和 .cpp 文件之间快速切换?

java - Hibernate 一对一映射

vim - 在可视模式下在行首粘贴数据

linux - 如何设置 Vim 为终端的十六色?

javascript - 将对象键和值映射到另一个对象

python - 获取单词与字典映射的所有结果

emacs - 如何将 evil-mode (vim 风格)宏保存到我的 init.el 中?

接受用户输入的 Vim 宏

r - 在 Vim R 插件中禁用下划线 "_"快捷方式插入 "<-"