[英]Vim map esc key in insert mode without losing undo sequence?
I have one question about Vim. 我有一个关于Vim的问题。 I understood map as just the equal command till now.
到目前为止,我一直将map理解为平等的命令。 Here's the thing.
就是这个 I put
imap <co> <esc>o
in my .vimrc
file to start a new line. 我将
imap <co> <esc>o
放在我的.vimrc
文件中以开始新行。 As to the reason why not just map <CR>
is that I followed the suggestion by Drew Neil that using esc
and o
command to replace so that I can use undo
command line by line. 至于为什么不仅仅映射
<CR>
的原因是我遵循了Drew Neil的建议,即使用esc
和o
命令来替换,以便可以逐行使用undo
命令行。 However, when I use <co>
to start a line, the undo
command doesn't work, which means Vim doesn't switch the mode even I map the <esc>
! 但是,当我使用
<co>
来开始一行时, undo
命令不起作用, 这意味着即使我映射了<esc>
, Vim也不会切换模式 ! I don't know whether is feature or bug of Vim? 我不知道Vim是功能还是bug? I will appreciate it if you help me in some ways.
如果您能以某种方式帮助我,我将不胜感激。
You can use inoremap <co> <cg>u<esc>o
to get the desired behaviour you want. 您可以使用
inoremap <co> <cg>u<esc>o
获得所需的行为。 <cg>u
breaks the current undo sequence (see :h i_CTRL-G_u
). <cg>u
中断当前的撤消序列(请参见:h i_CTRL-G_u
)。
I actually never thought about why having <esc>
in insert mappings doesn't count as breaking the undo sequence. 实际上,我从未想过为什么在插入映射中包含
<esc>
不会被视为破坏撤消序列。 I could certainly theorize why but doing so is dangerous in an SO answer, so I won't :) 我当然可以推理出为什么,但是这样做会很危险,所以我不会:)
Edited to add: Simpler would be: inoremap <co> <cg>u<cr>
编辑添加:更简单的是:
inoremap <co> <cg>u<cr>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.