2013-03-11 62 views
1

我有两部分关于vim映射的问题,例如imap和递归。在Vim中,映射既可以是右递归也可以是左递归或右递归,但不允许左递归,对吧?为什么不?我测试了以下实施例以说明我的意思:有关Vim映射中递归的规则是什么?

  1. (左递归)当我执行

    :imap x xyz 
    

    然后在插入模式的“x”,什么被输入到缓冲器

    xyz 
    

    据我所知,这种行为与我使用inoremap而不是imap时会发生的情况没有区别。

  2. (既不左也不是,右递归)当我执行

    :imap x yxz 
    

    然后在插入模式下输入 “X”,是什么(未遂是)放在缓冲区

    y...yz 
    
  3. (右递归)当我执行

    :imap x yzx 
    

    然后在插入模式下输入“X”是什么放于缓冲液(试图定)是

    yzyzyzyzyzyz... 
    
  4. (相互递归)当我执行

    :imap x abc 
    :imap a x 
    

    然后在插入模式 “X” 时,收到 “E223:递归映射”。

看来,我已经证明,Vim的禁止左递归映射和相互递归映射,但是我想验证:哪些规则中定义的Vim(可能相互)递归映射?

+2

但是...为什么?递归映射的唯一有效用法是使其适用,直到它在缓冲区末尾出错。 – 2013-03-11 07:46:43

+0

@IngoKarkat,为什么不呢? Vim允许它,所以我想知道它们是如何工作的。你确定你给的用例是* only *有效使用(可能是相互)递归映射吗? – BlueBomber 2013-03-11 20:12:50

回答

1

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}的前缀。