为什么此Vim映射的行为取决于进入可视模式的方式而有所不同? [英] Why does this Vim mapping behave differently depending on how Visual mode was entered?
问题描述
此问题是什么在这里提示了我的上一个问题: Vim的(插入)可视"模式?
This question is what prompted a previous question of mine here: Vim's '(insert) VISUAL' mode?
在该问题中,我询问了"VISUAL
"模式与"(insert) VISUAL
"模式之间的关系,在该模式下,您可以直接从插入模式进入可视模式.我发现一个映射的行为根据可视模式的子类型"而有所不同,但我不明白为什么:
In that question I asked about "VISUAL
" mode vs "(insert) VISUAL
" mode, which is where you enter visual mode directly from insert mode. I have found a mapping that behaves differently depending on the "subtype" of visual mode, and I don't understand why:
vnoremap x <Esc>jjj
vnoremap <A-[> <C-G>ugv
第一个映射说明了Vim如何使映射保持一致:从"VISUAL
"模式按 x 并从"(insert) VISUAL
模式会同时将光标向下移动3行.后者不会退出以进入插入模式并输入三个j
.因此,即使在映射之外,<Esc>
的行为也不会有所不同,即使它在映射之外的行为也不同于这两种模式.
The first mapping illustrates how Vim goes out of its way to make mappings to behave consistently: pressing x from "VISUAL
" mode and pressing x from "(insert) VISUAL
" mode will both move the cursor down 3 lines. The latter does not exit to insert mode and enter three j
's. So <Esc>
is not behaving differently depending on the mode, even though outside of a mapping it would behave differently from these two modes.
第二个映射说明了某些映射的行为不一致.如果突出显示一个单词并按 ALT + [",则在"VISUAL
"模式下将单词替换为ugv
,但在"<(insert) VISUAL
模式.大概是因为Vim正在执行撤消"和重新选择可视化"的普通模式命令ugv
.
The second mapping illustrates how some maps behave inconsistently. If you highlight a word and press ALT+[ then the word is replaced with ugv
if done from "VISUAL
" mode but nothing happens if done from "(insert) VISUAL
" mode. Presumably this is because Vim is executing the normal mode commands ugv
for 'undo' and 'reselect-visual'.
这是一个奇怪的不一致之处.这是调试映射时遇到的一个最小示例,并且想知道为什么这样做会如此.
This is a strange inconsistency. It is a minimal example I ran into when debugging my mappings, and would like to know why it works this way.
推荐答案
我可以复制您的示例,我认为您的分析是正确的.
I can reproduce your examples and I think your analysis is right.
当我从(插入)视觉模式键入 <C-G>ugv
时,我得到了预期的结果:<C-G>
切换到(插入)select 模式,ugv
用这些字符替换选择.映射的行为应相同.
When I type <C-G>ugv
from (insert) visual mode, I get the expected results: <C-G>
switches to (insert) select mode, ugv
replaces the selection with those characters. A mapping should behave in the same way.
我猜这是一个错误;整个(insert)子模式非常特殊,不经常使用,因此容易出现错误.您可以自己研究源代码,也可以在 vim_dev邮件列表中提出此问题.由于问题的含糊不清,尽管如此,可能很难吸引开发人员的很多兴趣.
I guess this is a bug; the entire (insert) submode is quite special, not frequently used, and therefore prone to bugs. You could delve into the source code yourself, or raise this issue on the vim_dev mailing list. Due to the obscurity of the issue, it may be hard to garner much interest from the devs, though.
这篇关于为什么此Vim映射的行为取决于进入可视模式的方式而有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!