1

I used to use the method suggested in this answer for swapping minus and underscore on Ubuntu 16, namely:

xmodmap -e "keycode 20 = underscore minus underscore minus"

This is not working for me on Debian 11. Is there another method that works?

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:    11
Codename:   bullseye

$ echo $XDG_CURRENT_DESKTOP
GNOME

This is the keyboard: keyboard

GChuf
  • 1,151
  • 9
  • 21
Neil
  • 11
  • 4

2 Answers2

0

The method you mentioned in your question works for me on Ubuntu 20.04.

However, you can try specifying keysyms instead of "minus" and "underscore" in your command, try if it works:

xmodmap -e "keycode 20 = 0x5f 0x2d"

0x2d should be the keysym for "minus" and 0x5f should be "underscore". You can check if this is true on your system with the xev command.

The first keysym in the command tells your system which key to execute when keycode 20 is pressed, and the second tells it what to execute when keycode 20 is pressed together with shift.

GChuf
  • 1,151
  • 9
  • 21
0

Option1: directly edit the file in /usr/share/X11/xkb/symbols/ for your layout. For example, it is /usr/share/X11/xkb/symbols/us. Search for minus, find:
key <AE11> {[ minus, underscore, quotedbl, plusminus ]}; // - _ " ±
replace it with:
key <AE11> {[ underscore, minus, quotedbl, plusminus ]}; // - _ " ±
Logout, login.

Option2: use xkb
(according to this unix.stackexchange answer by Pablo Saratxaga)

  1. create a file ~/.xkb/keymap/mykbd using:
    setxkbmap -print > ~/.xkb/keymap/mykbd

  2. create a file ~/.xkb/symbols/myswap with the contents (assuming again that you need to edit AE11):
    hidden partial alphanumeric_keys
    xkb_symbols "swap_minus_undersco" {
    key <AE11> {[ underscore, minus, quotedbl, plusminus ]};
    };

  3. edit the ~/.xkb/keymap/mykbd file, and change the xkb_symbols line to add:
    +myswap(swap_minus_undersco)

  4. load it:
    xkbcomp -I$HOME/.xkb ~/.xkb/keymap/mykbd $DISPLAY

Andra
  • 161
  • 1
  • 1
  • 8