简体   繁体   English

为什么在 Vim 中将 Esc 重新映射到 CAPS LOCK 如此复杂?

[英]Why is so complicated to remap Esc to CAPS LOCK in Vim?

I saw the vim wiki tips and it says that in order to remap Esc to CAPS LOCK you have to edit the following windows code:我看到了 vim wiki 提示,它说为了将 Esc 重新映射到 CAPS LOCK,您必须编辑以下 Windows 代码:

REGEDIT4
[HKEY_CURRENT_USER\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00

Is it possible to remap Esc to CAPS LOCK by only adding or modifying lines in the _vimrc?是否可以仅通过在 _vimrc 中添加或修改行来将 Esc 重新映射到 CAPS LOCK?

I recommend that you use AutoHotkey for this.我建议您为此使用 AutoHotkey。

You can do a per-application hotkey change:您可以更改每个应用程序的热键:

SetTitleMatchMode,2
#IfWinActive,VIM
   CAPSLOCK::ESC
return

#IfWinActive
   CAPSLOCK::CTRL
return

This script, for example sets caps to escape in vim, and control everywhere else.例如,此脚本将大写字母设置为在 vim 中转义,并控制其他任何地方。

There's no vim key identifier for the capslock key, so you have to do it with a scan code.大写锁定键没有 vim 键标识符,因此您必须使用扫描码来完成。

It would be like trying to map the ctrl key or the shift key to something - those keys don't do anything by themselves, they are key modifiers, so they can't be trapped the same way.这就像尝试将 ctrl 键或 shift 键映射到某个东西 - 这些键本身不会做任何事情,它们是键修饰符,所以它们不能以同样的方式被困住。

The mapping has to be done at the OS level instead of vim, so the complication comes from the OS.映射必须在操作系统级别而不是 vim 完成,因此复杂性来自操作系统。 For example, on my Ubuntu machine I have the following in ~/.Xmodmap :例如,在我的 Ubuntu 机器上,我在~/.Xmodmap有以下~/.Xmodmap

! Esc on caps lock
remove Lock = Caps_Lock
keysym Caps_Lock = Escape

However, I don't think the REGEDIT script is so bad.但是,我认为 REGEDIT 脚本并没有那么糟糕。 It's kind of ugly, but it's only two lines!有点丑,但只有两行!

Another alternative that worked well for me was to use the instructions found in this website另一种对我来说效果很好的替代方法是使用本网站中的说明

Essentially: Install Microsoft's Keyboard Layout Creator, then edit its source code to allow remapping of CAPS LOCK and create your own custom layout.本质上:安装 Microsoft 的键盘布局创建器,然后编辑其源代码以允许重新映射 CAPS LOCK 并创建您自己的自定义布局。

You could also use Ctrl-C to escape (Available at least in vim).您也可以使用 Ctrl-C 转义(至少在 vim 中可用)。 Which is what I normally use.这是我通常使用的。 I commonly swap control and capslock, though, and have done so through registry settings in windows and keyboard conf in ubuntu.不过,我通常会交换控制和大写锁定,并且是通过 Windows 中的注册表设置和 ubuntu 中的键盘配置来实现的。

Edit: as @mMontu kindly notes, Ctrl-C is more brutal than Esc: As stated in this appropriate question ,编辑:正如@mMontu 亲切地指出,Ctrl-C 比 Esc 更残酷:正如在这个适当的问题中所述

vim isn't going to bother checking if you just wrote part of an abbreviation, and it isn't going to run the fancy auto commands your plugins have set up for every time you leave insert mode vim 不会费心检查你是否只写了一个缩写的一部分,并且它不会在你每次离开插入模式时运行你的插件设置的花哨的自动命令

I hadn't noticed because my vimming is not so advanced yet.我没有注意到,因为我的 vimming 还没有那么先进。

Also you can try this: SharpKeys .你也可以试试这个: SharpKeys I swaped CapLock and Esc with it.我用它交换了 CapLock 和 Esc。

Remap CAPSLOCK to ESC and CTRL on Windows在 Windows 上将CAPSLOCK重新映射到ESCCTRL

A very nice tool that I've already described in this answer gives you the possibility to remap CAPSLOCK to both我已经在这个答案中描述的一个非常好的工具使您可以将CAPSLOCK重新映射到两者

  1. to ESC (when pressed alone) andESC (单独按下时)和
  2. to CTRL (when pressed with other keys)CTRL (当用其他键按下时)

Just use this little piece of open source software by ililim .只需使用ililim 的这个小小的开源软件

You do not need Admin privileges for this and ESC and CTRL are still working as expected.为此,您不需要管理员权限,并且ESCCTRL仍在按预期工作。

I use it to enjoy convenient CTRL + anything presses without hurting my pinky and to toggle modes in Vim that I use via ssh in MobaXterm.我用它来享受方便的CTRL + anything按下而不会伤害我的小指,并在 Vim 中切换我通过 MobaXterm 中的 ssh 使用的模式。 For installation just follow this description .安装只需按照此说明进行

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

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