Vim映射中关于递归的规则是什么?
关于vim映射,我有两个问题,例如imap和递归。在Vim中,映射可以是右递归的,也可以不是左递归的,也可以不是右递归的,但是它们不允许是左递归的,对吗?为什么不呢?我测试了以下示例来说明我的意思:Vim映射中关于递归的规则是什么?,vim,recursion,mapping,Vim,Recursion,Mapping,关于vim映射,我有两个问题,例如imap和递归。在Vim中,映射可以是右递归的,也可以不是左递归的,也可以不是右递归的,但是它们不允许是左递归的,对吗?为什么不呢?我测试了以下示例来说明我的意思: (左递归)当我执行 :imap x xyz :imap x yxz :imap x yzx :imap x abc :imap a x 然后在插入模式下键入“x”,输入到缓冲区的是 xyz y...yz yzyzyzyzyzyz... 据我所知,这种行为与我使用inoremap而不是i
:imap x xyz
:imap x yxz
:imap x yzx
:imap x abc
:imap a x
然后在插入模式下键入“x”,输入到缓冲区的是
xyz
y...yz
yzyzyzyzyzyz...
据我所知,这种行为与我使用inoremap而不是imap时所发生的情况是无法区分的:imap x xyz
:imap x yxz
:imap x yzx
:imap x abc
:imap a x
然后在插入模式下键入“x”,将(试图)放入缓冲区的内容为
xyz
y...yz
yzyzyzyzyzyz...
:imap x xyz
:imap x yxz
:imap x yzx
:imap x abc
:imap a x
然后在插入模式下键入“x”,将(试图)放入缓冲区的内容为
xyz
y...yz
yzyzyzyzyzyz...
:imap x xyz
:imap x yxz
:imap x yzx
:imap x abc
:imap a x
然后在插入模式中键入“x”,我收到“E223:递归映射”: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}的前缀时,仍然可以观察到该行为。From和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}的前缀时,仍然可以观察到该行为。但是……为什么?!递归映射的唯一有效用途是应用它,直到它在缓冲区末尾出错。@IngoKarkat,为什么不呢?Vim允许,所以我想知道它们是如何工作的。你确定你给出的用例是递归映射的唯一有效使用(可能是相互的)吗?但是…为什么?!递归映射的唯一有效用途是应用它,直到它在缓冲区末尾出错。@IngoKarkat,为什么不呢?Vim允许,所以我想知道它们是如何工作的。您确定您给出的用例是递归映射(可能是相互)的唯一有效使用吗?在最后一段中,{lhs}和{rhs}不应该互换吗?在最后一段中,{lhs}和{rhs}不应该互换吗?