windows 为什么在 Vim 中将 Esc 重新映射到 CAPS LOCK 如此复杂?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2145026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is so complicated to remap Esc to CAPS LOCK in Vim?
提问by alexchenco
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?
回答by Jay
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 中转义,并控制其他任何地方。
回答by Jansen Price
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 键映射到某个东西 - 这些键本身不会做任何事情,它们是键修饰符,所以它们不能以同样的方式被困住。
回答by permanuno
The mapping has to be done at the OS level instead of vim, so the complication comes from the OS. For example, on my Ubuntu machine I have the following in ~/.Xmodmap
:
映射必须在操作系统级别而不是 vim 完成,因此复杂性来自操作系统。例如,在我的 Ubuntu 机器上,我有以下内容~/.Xmodmap
:
! Esc on caps lock
remove Lock = Caps_Lock
keysym Caps_Lock = Escape
However, I don't think the REGEDIT script is so bad. It's kind of ugly, but it's only two lines!
但是,我认为 REGEDIT 脚本并没有那么糟糕。有点丑,不过只有两行!
回答by Adriano Varoli Piazza
You could also use Ctrl-C to escape (Available at least in 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.
您也可以使用 Ctrl-C 转义(至少在 vim 中可用)。这是我通常使用的。不过,我通常会交换控制和大写锁定,并且是通过 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 还没有那么先进。
回答by rp101
回答by graysonian
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 并创建您自己的自定义布局。
回答by Wolfson
Remap CAPSLOCK
to ESC
and CTRL
on Windows
重新映射CAPSLOCK
到ESC
与CTRL
在Windows
A very nice tool that I've already described in this answergives you the possibility to remap CAPSLOCK
to both
我已经在此答案中描述的一个非常好的工具使您可以重新映射CAPSLOCK
到两者
- to
ESC
(when pressed alone) and - to
CTRL
(when pressed with other keys)
- 到
ESC
(单独按下时)和 - to
CTRL
(当用其他键按下时)
Just use this little piece of open source softwareby ililim.
只要使用这个小片的开放源码软件的ililim。
You do not need Admin privileges for this and ESC
and CTRL
are still working as expected.
为此,您不需要管理员权限,ESC
并且CTRL
仍在按预期工作。
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. For installation just follow this description.
我用它来享受方便的CTRL + anything
按压而不伤害我的小指,并在 Vim 中切换我通过 MobaXterm 中的 ssh 使用的模式。安装只需按照此说明进行。