How to map Menu key (“Application key”) to Escape key in vim?

懵懂的女人 提交于 2019-12-10 20:43:01

问题


I think that using Menu key to quit vim's insert mode would be a great thing. It would be also nice to use Super key for that, but I'm not sure if it possible since Super key is a modifier.

Anyway, I couldn't find anything related to this. Looking for your help and thanks in advance!


回答1:


I don't think there's any way you can configure Vim to pay attention to the Menu key as such, but depending on your system there are various ways to turn the Menu key into an Escape key.

If you're using X11 on Linux:

  • The command xmodmap -e 'keycode 135 = Escape' will turn your Menu key into an Escape key for the current session, but is not permanent. To make it permanent under Gnome, you might try adding it under System → Preferences → Startup Applications.
  • The xkeycaps program will give you a GUI for similar remappings.

For more information:

http://46dogs.blogspot.com/2008/05/remap-keys-in-ubuntu-804-hardy-heron.html

http://ubuntuforums.org/archive/index.php/t-106209.html




回答2:


Just try using ctrl+[ instead of binding another key. This combination is a standard one in vim, btw.

This is even easier when having rebound capslock into an additional ctrl.




回答3:


I haven't found a way to map it in gVim yet, but I was able to successfully map the Menu key in a urxvt+screen+vim stack by the following method:

  1. In a terminal, type Ctrl+v and press Menu. This is mapped to the quoted-insert function in Zsh and in Readline-based tools like Bash.
  2. It will generate an escape sequence like ^[[29~ at the prompt. (The initial ^[ must be translated to <Esc> for use in .vimrc.)
  3. Open up .vimrc and add a line like this:
imap <Esc>[29~ <Esc>

(or imap <Esc>[29~ <Esc><Esc> if you don't want it to wait for further input like the Escape key does.)

Note that not all keys return something usable from Ctrl+v. This is a limitation of terminal emulators and can be remedied by remapping the key. You may be able to do that at the level of the terminal emulator rather than for all X apps.

For example, for urxvt, I had to add the following lines to ~/.Xresources and run xrdb -merge ~/.Xresources to apply them:

! Unbreak zsh keys in URxvt
URxvt*keysym.Home: \033[1~
URxvt*keysym.End: \033[4~

(\033 is <Esc> in ~/.Xresources syntax.)



来源:https://stackoverflow.com/questions/4271475/how-to-map-menu-key-application-key-to-escape-key-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!