You are not logged in.
Pages: 1
Hi everyone,
I would be grateful if you could help me out to separate Ctrl, which Vim ties to the Caps lock key. Regardless of whether I modify the position of the Caps lock in a xkb keymap layout, in Vim, I consistently press both the Caps lock and Ctrl simultaneously.
Problem
When I press the Ctrl key on a keyboard, Vim doesn't react to the keystroke. To press Ctrl in Vim, usually in combination with another key, I have to press the Caps lock key. This is an issue for me. (1) I switch the caps lock mode on or off, system-wide. (2) I need to press the Caps lock key to press the Ctrl key for Vim. I am able to execute combinations of <C-w> or <C-v> as intended, although the event (1) happens every key press and it is a headache. After the combination is executed, I need to undo the Caps lock mode every time to further use Vim. It is case-sensitive; it reacts differently on :w, :s vs. :W, :S, <C-v> vs. <C-V>, and furthermore.
Here are selected things I've found from a solving process:
I have confirmed the problem happens in Vim versions of 9.1.0611-1, 9.1.0532-1 and 9.1.0151-2.
Clean installation from the Pacman with Vim's default configuration.
I have the same problem on a second Arch Linux device with slightly different installed packages.
A display server is Xorg.
I use xkbmap to map keyboard a layout.
Being in a virtual console makes no difference.
Vim continues to bind Ctrl to Caps Lock when Caps Lock is remapped. Vim doesn't perceive Ctrl when Caps Lock is not mapped.
I found it during troubleshooting where I tested multiple xkbmap layouts. Initially I thought the problem was in -option ctrl:swapcaps flag. Vim respects the Ctrl swap and doesn't respect the Caps lock swap. This was rejected. As you can see in the code block, it proved to not be the problem because I tried the simple different keyboard layouts.
With the caps:swapescape option, Vim reacted in the same problematic way. 1/ It respected the system-wide remap. I had a Caps lock on the Esc key, and I had to press the remapped Caps lock on the Esc key to press "Ctrl" in Vim to execute <C-v>, <C-a>. 2/ the issue isn't gone. I changed the caps lock mode on or off.
With the ctrl:nocaps option, I didn't have a Caps lock key system-wide. By pressing Caps lock, Ctrl, or nearly anything, 1/ there was no Caps lock key switch system-wide. 2/ In Vim, Vim didn't react to the Caps lock key and Ctrl key combo, and I didn't execute <C-v>, <C-a> combinations. It felt like if you wouldn't have Ctrl on your keyboard at all.
### xkbcli interactive-x11
### "keycode" is how "keysyms" computer perceive. "keysyms" is a physical pressed key.
### Below are outputs of different layout.
### I pressed physical left control key 2 times, then I pressed physical caps lock key 2 times.
# setxkbmap us -option
keycode [ LCTL ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ LCTL ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ CAPS ] keysyms [ Caps_Lock ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ CAPS ] keysyms [ Caps_Lock ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Lock Mod2 ] leds [ Caps Lock Num Lock ]
# setxkbmap us -option ctrl:swapcaps
keycode [ CAPS ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ CAPS ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ LCTL ] keysyms [ Caps_Lock ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ LCTL ] keysyms [ Caps_Lock ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Lock Mod2 ] leds [ Caps Lock Num Lock ]
# setxkbmap us -option caps:swapescape
keycode [ LCTL ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ LCTL ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ ESC ] keysyms [ Caps_Lock ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ ESC ] keysyms [ Caps_Lock ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Lock Mod2 ] leds [ Caps Lock Num Lock ]
# setxkbmap us -option ctrl:nocaps
keycode [ LCTL ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ LCTL ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ CAPS ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]
keycode [ CAPS ] keysyms [ Control_L ] unicode [ ] layout [ English (US) (0) ] level [ 0 ] mods [ Mod2 ] leds [ Num Lock ]Similar topics
[Solved] Switching Caps-Lock and Escape with xmodmap, doesn't work
Same issue in a different environment: Mapping caps lock to Esc has issues
Last edited by finebread (2024-07-31 17:22:30)
Offline
Being in a virtual console makes no difference.
Sanity check: same issue w/ right control or a different keyboard?
Some system checks
setxkbmap -print -query
xev -event keyboard # output for pressing ctrl and caps
libinput debug-events # dto
evtest # dtotoDo you run https://archlinux.org/packages/extra/x86_64/keyd/ or the likes?
Offline
Sanity check: same issue w/ right control or a different keyboard?
Tried different keyboard, Vim reacts the same.
Right control Vim doesn't react to. In other software the right control works like ctrl.
Do you run https://archlinux.org/packages/extra/x86_64/keyd/ or the likes?
I don't run keyd. I use only xmodmap to swap tilda with esc.
____
Some system checks
My usual setxkmap is this what you see in -print -query. This layout I further use in following checks:
setxkbmap -print -query.
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwertz)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+cz(qwerty)+inet(evdev)+ctrl(swapcaps)" };
xkb_geometry { include "pc(pc104)" };
};
rules: evdev
model: pc104
layout: cz
variant: qwerty
options: ctrl:swapcapsxev -event keyboard pastebin.
libinput debug-events pastebin.
evtest pastebin.
Since my post I found one spot in Vim that works as intended. Pressing the caps lock key where I have mapped ctrl and v I execute the --visual block--, <C-v>. No caps lock switch. Visual line works as well. by pressing caps lock on ctrl key and v, to call <V>.
Last edited by finebread (2024-07-28 15:54:42)
Offline
ctrl acts as caps lock because of "ctrl:swapcaps" (is this seriously what you want, do you use the caps lock at all?) and triggers the LED and state switch.
Edit: from your OP "probably not"?
What do things look like if you don't swap anything and use use a regular keymap w/o further options?
Edit #2: since this seems very vim specific, post your vimrc, you might have remapped the soft caps lock and trigger that w/ whatever shortcuts else you're testing.
I assume the intention was to use the caps lock key for something else in vim??
Also test the behavior w/o your personal vimrc
Last edited by seth (2024-07-28 16:40:12)
Offline
With "ctrl:swapcaps" ctrl acts as caps lock and caps lock acts as ctrl. It works system-wide, only in Vim not.
With a regular keymap without further options the state is unchanged. The keymap works as intended, in vim I need to press caps lock to press ctrl in vim and that turns on caps. With ctrl:nocaps I don't have ctrl in vim. See my code block in the initial post where I've tried regular keymaps w/ and w/o options.
To edit #2 paragraph: I don't have vimrc. I can't post it. The caps lock intention is to move it to where ctrl is system-wide. Not in vim explicitly.
I agree it is very vim specific. Do you think after checks there is something related to Arch Linux or the solution lies in vim programme?
Offline
Sanity checks:
1. is this actually vim (what you run in some terminal) or gvim (w/ a GUI around it)
2. X11 or xwayland
3. In case of actually-vim-vim, what TE and does it matter which one you use?
4. do you still xmodmap (notably modifiers)? "xmodmap -pm"
Offline
I use vim in a terminal.
X11.
If TE is an abbreviation for text editor, I use vim. It does matter. It is a good hint to try out different text editor. Thank you.
I tried nano text editor. With the classic us key layout it works as you would expect. With swapped ctrl and caps locks "ctrl:swapcaps" nano works too.
To counterweight, the problem prevails in classic vi. Both in the terminal and virtual console, different tty, keymaps.
"xmodmap -pm".
xmodmap: up to 4 keys per modifier, (keycodes in parentheses):
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x25)
control Control_L (0x42), Control_R (0x69)
mod1 Alt_L (0x40), Alt_L (0xcc), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod3 ISO_Level5_Shift (0xcb)
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c)Offline
"Terminal Emulator" - like xterm, urxvt, gnome-terminal, st, the thing you run vim in ![]()
Offline
I see. The terminal emulator is st.
I tried vim in xterm and same results.
Offline
Have you tried the behavior w/ a fresh user to isolate whether it's your config or system-wide?
Then let's focus on this condition:
Vim doesn't perceive Ctrl when Caps Lock is not mapped.
non-gui vim inside st (any terminal) gets the key from the terminal, not the display server - a very popular way to screw this up is to export TERM to a false value. (Though if you're also facing this w/ xterm that becomes less likely)
"Doesn't perceive" ctrl at all? I guess your metric is that the desired action doesn't get triggered?
=> What does ctrl+c?
Offline
I tried a fresh user and the behavior was the same.
Thank you for the information speaking about how vim gets from the terminal. st TERM is st-256colors, xterm TERM is xterm.
=> What does ctrl+c?
with setxkbmap us -option ctrl:nocaps, pressing normal ctrl+c vim says to me Type :qa! and press <Enter> to abandon all changes and exit Vim. With ctrl:swapcaps, it says the same line when I press capslock+c, where ctrl is mapped.
Offline
pressing normal ctrl+c vim says to me Type :qa! and press <Enter> to abandon all changes and exit Vim
which is exactly what you'd expect, are tehre any unwanted side effects? And what about
Vim doesn't perceive Ctrl when Caps Lock is not mapped.
What's you're actual metric (test, shortcut, what do you expect, what happens instead) for that?
Offline
Your two questions lead to one point. What do I aim for? I had done vim checks again and I found out I was wrong with vim commands. It was me who tied ctrl to caps lock, not Vim or Arch Linux. Indeed I get a visual line <V> when I press caps lock and v, not ctrl+v. Or <A> via capslock+a and other single letter characters. I thought I need to ctrl+v to get to the visual line and so forth. I confirm other ctrl+… commands work as we would expect.
Thank you Seth for your conversation. You progressed me via checks, cut potential error paths, prompt responses. You helped me out and I have learnt during the way
.
Happy to close my thread and mark as solved.
Offline
Happy to close my thread and mark as solved.
![]()
You can mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Offline
Pages: 1