Simplest way to swap esc key with ` key

You want to follow the five-point list of instructions on the ubuntuforums by Andy Meier: http://ubuntuforums.org/showthread.php?p=10286878#post10286878

The keys you'd have to modify in your /usr/share/X11/xkb/symbols/mynewlayout would be:

key <ESC> {[ quoteleft, asciitilde ] };

key <TLDE> {[ escape ] };

You then have to register this new layout as described on the forum. Good luck.


Xmodmap replaces keycodes. shift+esc is not a different key. Check the output of xev when you press a and shift+a. You'll find the state changes from 0x0 to 0x1 while the keycode stays the same. What you want to do is change the definition of a key, not just tack on the A/a or ~/` keys. Redefining the output of key's state change is outside the scope of xmodmap.

I don't know exactly how to do what you want, but I think creating a keyboard definition is the right way. I'll edit with more help if or when I figure out how to do this. Maybe this will set you on the right path.


I read elsewhere that Ubuntu is no longer using xmodmap. It's using xkb instead. There's some info on that in this post:

Permanent xmodmap in Ubuntu 13.04

However, I'm still using 12.04LTS, and I wanted to swap my Esc and grave keys. I did it with xmodmap and it worked.

I created a small script that runs xmodmap and I have that script run when I login. The xmodmap commands are:

xmodmap -e "keycode 49 = Escape"
xmodmap -e "keycode 9 = grave asciitilde"

I don't know if this solution will work in versions of Ubuntu newer than 12.04.