[英]What are the rules regarding recursion in Vim mappings?
我在两部分中有一个关于vim映射的问题,例如imap和递归。 在Vim中,映射既可以是右递归的,也可以是左递归的,也不能是右递归的,但是不允许它们是左递归的,对吗? 为什么不? 我测试了以下示例以说明我的意思:
(左递归)执行时
:imap x xyz
然后在插入模式下键入“ x”,输入到缓冲区的是
xyz
据我所知,这种行为与使用inoremap而不是imap会发生的情况没有区别。
(无论是左还是右递归)当我执行
:imap x yxz
然后在插入模式下键入“ x”,将(尝试)放入缓冲区的是
y...yz
(正确的递归)当我执行
:imap x yzx
然后在插入模式下键入“ x”,将(尝试)放入缓冲区的是
yzyzyzyzyzyz...
(相互递归)执行时
:imap x abc :imap ax
然后在插入模式下键入“ x”,我会收到“ E223:递归映射”。
看来我已经证明了Vim不允许左递归映射和相互递归映射,但是我想验证一下: 在Vim中定义(可能是相互)递归映射的规则是什么?
从http://vim.wikia.com/wiki/Recursive_mappings和vim命令
:help recursive_mapping
If you include the {lhs} in the {rhs} you have a recursive mapping. When
{lhs} is typed, it will be replaced with {rhs}. When the {lhs} which is
included in {rhs} is encountered it will be replaced with {rhs}, and so on.
This makes it possible to repeat a command an infinite number of times ...
There is one exception: If the {rhs} starts with {lhs}, the first character
is not mapped again (this is Vi compatible) ... For example, if you use:
:map x y
:map y x
Vim will replace x with y, and then y with x, etc.
When this has happened 'maxmapdepth' times (default 1000),
Vim will give the error message "recursive mapping".
看来,文档仅涉及{lhs}是单个字符的映射,但是当{lhs}多于一个字符并且是{rhs}的前缀时,仍会观察到该行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.