[英]VIM Mapping doesn't work properly when I create macros
I started studying VIM around 3 days ago.大约 3 天前,我开始研究 VIM。 And now I'm stuck creating macros.
现在我被困在创建宏中。
On the beginning of learning VIM I created mapping: jk -> ESC for convenience ( inoremap jk <ESC>
).在开始学习 VIM 时,我创建了映射: jk -> ESC为了方便(
inoremap jk <ESC>
)。 Now my macros works correctly only if I pressed ESC ;现在我的宏只有在我按下ESC时才能正常工作; with jk they don't work properly.
与jk他们不能正常工作。
For example I create macros to add :
to the beginning and end of line:例如,我创建宏以将
:
添加到行的开头和结尾:
'I' + ':' + 'ESC' + 'A' + ':' + 'ESC'
@a macros: I exited insert mode with jk
. @a 宏:我用
jk
退出了插入模式。
@b macros: I exited insert mode with <ESC>
. @b 宏:我用
<ESC>
退出了插入模式。
If apply @a
to the line example
, I don't get the colon at the end... I end up with:如果将
@a
应用于行example
,我最后没有得到冒号......我最终得到:
:example
If apply @b
to the line example
, I do get the colon at the end... I end up with:如果将
@b
应用于行example
,我会在最后得到冒号......我最终得到:
:example:
Output of command - :registers
(macros aren't the same): Output 命令 -
:registers
(宏不一样):
~/.vimrc
: ~/.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
Q: How to make behavior of 'jk' and 'ESC' equal when recording macros.问:录制宏时如何使“jk”和“ESC”的行为相等。
PS Sorry if the explanation is not smooth, this is my first question and I tried to make it as simple as possible. PS对不起,如果解释不顺利,这是我的第一个问题,我试图让它尽可能简单。
You need to move the comment up.您需要将评论向上移动。
Instead of代替
inoremap jk " type 'jk' for leaving insert mode
Do做
" type 'jk' for leaving insert mode inoremap jk
Vim interprets this comment as part of your mapping. Vim 将此注释解释为映射的一部分。
Related: https://vi.stackexchange.com/a/6922相关: https://vi.stackexchange.com/a/6922
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.