“M-” bindings in vim on iTerm2/Terminal don't work

后端 未结 2 1840
悲&欢浪女
悲&欢浪女 2020-12-09 04:00

I noticed that iTerm2 offers the very convenient feature of using \"Option key as +ESC\" (or as meta, but apparently that\'s obsolete).

I tried them both and the op

相关标签:
2条回答
  • 2020-12-09 04:40

    I left my option key to act as Normal and discovered that Vim saw them as <T- bindings. So, for example, I have this mapping setup in my .vimrc to move to the end of a word when in Insert mode:

    noremap! <T-Right> <C-o><Right>;
    
    0 讨论(0)
  • 2020-12-09 04:50

    I've downloaded the latest iTerm2 and tried to see what it sent to/what was printed by Vim (i<C-v><M-a>) with the following settings:

    • Option as Option:

      Vim prints æ which is normal and expected on my french keyboard

    • Option as Meta:

      Vim stays there, waiting for something to happen. Nothing is printed. If I press Option and a in sequence I just obtain a. Pressing Option and a in some random order may print á, which is weird and totally unexpected.

    • Option as +ESC:

      Vim prints ^[a which means "Escape character followed by the character a".

    From these tests it appears that Vim will never ever receive <M-> without some hypothetical black magic.

    If you stick with "Option as +ESC", it seems that you will have to change all your custom <M-something> mappings to <Esc>something. This may work but it will make writing any kind of prose in any non-english language a pain.

    What I do: I leave the Option key as it is so that I can type characters like œ…«» easily and I use <Leader> (mapped to ,, see :help mapleader) for all my custom mappings.

    Some people here like to reserve it for plugins and advocate a somewhat simpler and potentially safer approach.

    inoremap <leader>, <C-x><C-o> "my way (copied elsewhere)
    inoremap ,, <C-x><C-o>        "another way
    
    0 讨论(0)
提交回复
热议问题