简体   繁体   English

如何将菜单键(“应用程序键”)映射到 vim 中的退出键?

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

I think that using Menu key to quit vim's insert mode would be a great thing.我认为使用 Menu 键退出 vim 的插入模式将是一件好事。 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.使用 Super 键也很好,但我不确定是否可能,因为 Super 键是一个修饰符。

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.我认为没有任何方法可以将 Vim 配置为关注 Menu 键,但是根据您的系统,有多种方法可以将 Menu 键转换为 Escape 键。

If you're using X11 on Linux:如果您在 Linux 上使用 X11:

  • The command xmodmap -e 'keycode 135 = Escape' will turn your Menu key into an Escape key for the current session, but is not permanent.命令xmodmap -e 'keycode 135 = Escape'会将您的菜单键变成当前会话的 Escape 键,但不是永久的。 To make it permanent under Gnome, you might try adding it under System → Preferences → Startup Applications.要使其在 Gnome 下永久存在,您可以尝试在系统 → 首选项 → 启动应用程序下添加它。
  • The xkeycaps program will give you a GUI for similar remappings. xkeycaps程序将为您提供用于类似重新映射的 GUI。

For more information:想要查询更多的信息:

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

http://ubuntuforums.org/archive/index.php/t-106209.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:我还没有找到在 gVim 中映射它的方法,但是我能够通过以下方法成功映射urxvt + screen + vim堆栈中的 Menu 键:

  1. In a terminal, type Ctrl + v and press Menu .在终端中,键入Ctrl + v并按Menu This is mapped to the quoted-insert function in Zsh and in Readline-based tools like Bash.这映射到 Zsh 和基于 Readline 的工具(如 Bash)中的quoted-insert函数。
  2. It will generate an escape sequence like ^[[29~ at the prompt.它会在提示符下生成一个类似^[[29~的转义序列。 (The initial ^[ must be translated to <Esc> for use in .vimrc .) (首字母^[必须转换为<Esc>以在.vimrc使用。)
  3. Open up .vimrc and add a line like this:打开.vimrc并添加如下一行:
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.) (或imap <Esc>[29~ <Esc><Esc>如果您不希望它像 Escape 键那样等待进一步输入。)

Note that not all keys return something usable from Ctrl + v .请注意,并非所有键都从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.您可以在终端模拟器级别而不是所有 X 应用程序级别执行此操作。

For example, for urxvt , I had to add the following lines to ~/.Xresources and run xrdb -merge ~/.Xresources to apply them:例如,对于urxvt ,我必须urxvt添加到~/.Xresources xrdb -merge ~/.Xresources并运行xrdb -merge ~/.Xresources来应用它们:

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

( \\033 is <Esc> in ~/.Xresources syntax.) \\033~/.Xresources语法中的<Esc> 。)

Just try using ctrl + [ instead of binding another key.只需尝试使用ctrl + [而不是绑定另一个键。 This combination is a standard one in vim, btw.这种组合是vim中的标准组合,顺便说一句。

This is even easier when having rebound capslock into an additional ctrl .当将大写锁定回弹到额外的ctrl时,这更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM