How to map Menu key ("Application key") to Escape key in vim?
I think that usi开发者_高级运维ng 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!
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
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:
- 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. - It will generate an escape sequence like
^[[29~
at the prompt. (The initial^[
must be translated to<Esc>
for use in.vimrc
.) - 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.)
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.
精彩评论