簡體   English   中英

關於Vim映射中的遞歸的規則是什么?

[英]What are the rules regarding recursion in Vim mappings?

我在兩部分中有一個關於vim映射的問題,例如imap和遞歸。 在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 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM