2013-03-11 42 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}的前綴。