1

vimマッピングについて、imapと再帰などの2つの部分で質問があります。Vimでは、マッピングは右再帰でも左再帰でも右再帰でもありませんが、左再帰にすることはできませんよね?なぜだめですか?次の例をテストして、意味を説明しました。

  1. (左再帰)実行すると

    :imap x xyz
    

    次に、挿入モードで「x」と入力します。バッファに入力されるのは次のとおりです。

    xyz
    

    私の知る限り、この動作は、imapの代わりにinoremapを使用した場合に発生する動作と区別がつきません。

  2. (左にも右にも再帰的ではありません)実行すると

    :imap x yxz
    

    次に、挿入モードで「x」と入力します。バッファに入れられる(試行される)内容は次のとおりです。

    y...yz
    
  3. (右再帰)実行すると

    :imap x yzx
    

    次に、挿入モードで「x」と入力します。バッファに入れられる(試行される)内容は次のとおりです。

    yzyzyzyzyzyz...
    
  4. (相互再帰)実行すると

    :imap x abc
    :imap a x
    

    次に、挿入モードで「x」と入力すると、「E223:再帰的マッピング」が表示されます。

Vimが左再帰マッピングと相互再帰マッピングを禁止していることを示したようですが、確認したいと思います:Vimで(おそらく相互に)再帰マッピングを定義するためのルールは何ですか?

4

1 に答える 1

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}のプレフィックスである場合でも動作は観察されます。

于 2013-03-11T00:56:15.753 に答える