我大约 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:
~/.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/