Sunday 30 March 2014

Vim が NUL を受け取った場合

Vim のインサートモードで何者でもないキーに当たると微妙な挙動する件.
何を言ってるかわからないと思いますが個人的メモなので気にしない.


さて現在使ってるのは US キーボード,ただしハード的にはノートPCのそれで,どうやらキーマップのないキーが出来ている.場所は backspace の左隣,\ とか | が刻印されているキーだ.xev で確認してみると
state 0x0, keycode 132 (keysym 0x0, NoSymbol)
になっている.
さてところで,Vim のインサートモードでこのキーに指が当たると若干見慣れない動作をする.
  • $ vim -> i<このキー>E29: No inserted text yet
  • $ vim -> ifoo<ESC>o<このキー> で 2行目に foo が出現
なんなんだろうとか気になってたんだけど結果はあっけなかった.
まずはキーマップをどう認識してるか確認
  • $ vim -> i<C-v><このキー>^@
確かに NUL でございますな.
ほんとならここで気付けばよかったんだろうけど,:help E29
*quote_.* *quote.* *E29*
    ".  Contains the last inserted text (the same as what is inserted
        with the insert mode commands CTRL-A and CTRL-@).  Note: this
        doesn't work with CTRL-R on the command-line.  It works a bit
        differently, like inserting the text instead of putting it
        ('textwidth' and other options affect what is inserted).
:help i_CTRL-@
CTRL-@      Insert previously inserted text and stop insert.  {Vi: only
        when typed as first char, only up to 128 chars}
:help NUL
notation    meaning         equivalent  decimal value(s)    ~
-----------------------------------------------------------------------
<Nul>       zero            CTRL-@    0 (stored as 10) *<Nul>*
つまり「キーマップないよ」→「NUL ですこんにちは」→「Ctrl-@ だよー」→「ほいほいもう一回インサートねー」とのこと.
ありがとうございました.

No comments:

Post a Comment