在 Vim 中阻止错误的 Shift 键

在 Vim 中阻止错误的 Shift 键

我知道我应该用右 Shift 键来输入我用左手输入的字母。但我经常只用右手输入冒号,将无名指移到 Shift 键上,将食指移到冒号键上。

我想强迫自己停止这种行为,至少在 Vim 中是这样。有什么方法可以阻止我使用“右移”和“Q”吗?

答案1

地图可以做你要求的事情,只要你不介意弄坏你的CapsLock钥匙。

Xmodmap 可以区分左、右 Shift 键,因此我们可以初步重新映射RightShiftModeSwitch以下方式:

xmodmap -e "keysym Shift_R = Mode_switch"

修改键行为的基本语法是

xmodmap -e "keycode  KEYCODE = KEYSYMBOL1 KEYSYMBOL1 KEYSYMBOL3 KEYSYMBOL4"
xmodmap -e "keysym KEYSYMBOL = KEYSYMBOL1 KEYSYMBOL1 KEYSYMBOL3 KEYSYMBOL4"

在哪里

  • KEYSYMBOL2按下 的同时按下 键时触发Shift
  • KEYSYMBOL3按下 的同时按下 键时触发ModeSwitch
  • KEYSYMBOL4Shift在按下+ 的同时按下 键时触发ModeSwitch
  • KEYSYMBOL1当按下不包含上述任何一项的键时会被触发。
  • ModeSwitchAltGr默认的(仅适用于某些键盘布局)。

理论就讲这么多。实际上,在修改Shift+Letter组合时,这些重新映射的行为可能会有所不同。我不能代表 Kubuntu 发言,但某些 Unity 应用程序在这些情况下会覆盖 Xmodmap 指定的行为。

要重新配置每个键以仅接受适当的修饰符,我发现最强大的方法是:

  • 为了使R仅接受RightShift,请执行以下命令:

    xmodmap r r R R
    
  • 为了使L仅接受LeftShift,请执行以下命令:

    xmodmap l L l l
    

尖端:

  • 为了使重新映射永久生效,请在中创建/编辑一个 shell 脚本~/.kde/Autostart/,使其可执行并在其中保存相应的命令。

  • 要撤消所有重新映射,只需执行以下命令:

    setxkbmap
    

答案2

我写了一个脚本来实现 Dennis 的想法(这是英国ascii 键盘,应该很容易修改为美国键盘)

! A script to rebind all shifted keys to force you to use the correct shift
! button for minimum risk of rsi.

! Buttons not really on either side, make either shift work:
keysym 6 = 6 asciicircum asciicircum asciicircum
keysym y = y Y Y Y
keysym b = b B B B


! Might need to replace 0x3571 with a keysym which is not used elsewhere in
! your key map so that pressing the wrong key generates nothing. This
! keysym should be fine for most people. Note: this may interfere with
! emacs in annoying ways because emacs because it print warnings when
! undefined keys are pressed, the answer is to learn not to press them!


! Set right shift to be a sort of temporary caps lock (only on while button held)
keysym Shift_R = Mode_switch


! Bind lhs of keyboard to only work with this "temporary caps lock
! modifier" as shift and rhs to only work with Shift_L.

! lhs letters
keysym q = q 0x3571 Q Q
keysym w = w 0x3571 W W
keysym e = e 0x3571 E E
keysym r = r 0x3571 R R
keysym t = t 0x3571 T T
keysym a = a 0x3571 A A
keysym s = s 0x3571 S S
keysym d = d 0x3571 D D
keysym f = f 0x3571 F F
keysym g = g 0x3571 G G
keysym z = z 0x3571 Z Z
keysym x = x 0x3571 X X
keysym c = c 0x3571 C C
keysym v = v 0x3571 V V

! lhs symbols
keysym backslash = backslash 0x3571 bar bar
keysym grave = grave 0x3571 notsign notsign
keysym 1 = 1 0x3571 exclam
keysym 2 = 2 0x3571 quotedbl
keysym 3 = 3 0x3571 sterling
keysym 4 = 4 0x3571 dollar
keysym 5 = 5 0x3571 percent

! rhs letters
keysym u = u U 0x3571 U
keysym i = i I 0x3571 I
keysym o = o O 0x3571 O
keysym p = p P 0x3571 P
keysym h = h H 0x3571 H
keysym j = j J 0x3571 J
keysym k = k K 0x3571 K
keysym l = l L 0x3571 L
keysym n = n N 0x3571 N
keysym m = m M 0x3571 M

! rhs symbols
keysym 7 = 7 ampersand 0x3571 ampersand
keysym 8 = 8 asterisk 0x3571 asterisk
keysym 9 = 9 parenleft 0x3571 parenleft
keysym 0 = 0 parenright 0x3571 parenright
keysym minus = minus underscore 0x3571 underscore
keysym equal = equal plus 0x3571 plus
keysym bracketleft = bracketleft braceleft 0x3571 braceleft
keysym bracketright = bracketright braceright 0x3571 braceright
keysym semicolon = semicolon colon 0x3571 colon
keysym apostrophe = apostrophe at 0x3571 at
keysym numbersign = numbersign asciitilde 0x3571 asciitilde
keysym comma = comma less 0x3571 less
keysym period = period greater 0x3571 greater
keysym slash = slash question 0x3571 question

要使用它:保存在文本文件中并运行:

xmodmap [script_name]

另外,更有声誉的人是否可以修改丹尼斯的答案以替换

xmodmap r r R R

xmodmap -e 'keysym r = r r R R'

和同样地L,这是实际需要的命令。

相关内容