2

很多人都询问写过如何映射Caps LockEscor Control,但我想使用该Caps Lock键作为插入模式和正常模式之间的切换,我还没有找到任何解决如何做到这一点的东西。

(然后我想做ShiftCaps Lock一个Caps Lock人通常会做的事情,对于那些罕见的时候你需要Caps Lock,比如在输入长的 CONSTANT 名称时。但这真的是一个单独的问题,如果真的有办法完成的话,我稍后会谈到第一部分。所有这一切很可能是不可能的。)

这些天我主要在工作中使用 Windows,所以这是我目前最关心的。(由于这可能涉及某种仅限于 Windows 的黑客行为,因此我将针对我也使用的 OS X 提出一个单独的问题。)

4

2 回答 2

2

您的请求不寻常,我建议您不要过多地偏离默认模式切换,但您可以尝试以下操作:

  1. 首先,使用操作系统特定的方法(如您提到的链接中所述),您需要将您的Caps Lock密钥重新映射到另一个(未使用的,例如F12)密钥,因为特殊的 Caps Lock 不能在 Vim 中重新映射。
  2. 然后,为改变模式的重新映射键定义两个 Vim 映射。

这是一个简单的例子:

:nnoremap <F12> a
:inoremap <F12> <Esc>

然后,您可以使用 Caps Lock 键(重新映射到 F12)在插入模式和命令模式之间切换。

于 2012-11-02T16:11:06.353 回答
1

I don't think you can do this natively with Vim, but It looks like you could probably do this using AutoHotKey. I'm not an Autohotkey expert, but here's what I slapped together:

Taken from the example here:

This script uses Capslock key to give a hotkey 2 different outputs. I'm not sure if you need to use +; instead of : in the second part to switch to command mode.

n=0
Capslock::
On := 1
If On=True {
Send i
On := False
} Else {
Send :
On := True
}
Return

The above script is untested, but should switch between sending i (for insert) or : (to insert command mode). Unfortunately this won't keep track of the current state VIM is in. You'd have to learn my AHK scripting for that (how to use variables, so when in insert and you hit keys like '?', '/', 'esc', ':', etc it would know to variable used to store the VIM mode in AHK as well as send the real code).

References:

http://www.autohotkey.com/board/topic/68710-autohotkey-toggle-state-function/ http://www.autohotkey.com/docs/commands/SetNumScrollCapsLockState.htm http://www.autohotkey.com/board/topic/42379-toggle-key/

For your second part it looks like it could be done with something like:

http://www.autohotkey.com/board/topic/51215-completely-disable-capslock/ http://www.autohotkey.com/board/topic/61-use-capslock-as-a-toggle/ http://www.autohotkey.com/board/topic/68710-autohotkey-toggle-state-function/

Not totally sure but you made to do the registry edit for VIM to recognize the Capslock change correctly:

http://www.autohotkey.com/docs/misc/Remap.htm#

于 2012-11-02T23:42:39.777 回答