keymap swap underscore and dash

I have noticed that when coding I type underscores much more often then dashes. Is it possible to swap these keycodes so I can type shiftless underscores? I am using linux (chromebook developer mode).


Solution 1:

I'm surprised there wasn't more about this specific remapping out there, considering how popular snake_case is.

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

and to get back to normal:

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

For anyone wanting to map other keys, see: https://wiki.archlinux.org/index.php/Xmodmap

Basically, run xmodmap -pke to see what the keys are currently mapped to (it gives you the same format as the commands I wrote above), and use xmodmap -e to make your changes.