Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the simplest way to swap the functionality of the Esc key and the ` key?
System ➜ Preferences ➜Keyboard ➜ Layouts ➜ Options let me swap my Ctrl key and Capslock key, which was good, but it doesn't seem to let me do other keys in a generalized way.

The xmodmap answer that got accepted here was useful. Now my ` key is on the physical Esc key, and vice versa. The problem is that when I Shift+Esc I still only get a ` when I'd like to get a tilde.

share|improve this question
FYI: Escape the backtick and other special characters like this: \` – djeikyb Apr 4 '11 at 9:07
up vote 6 down vote accepted

You want to follow the five-point list of instructions on the ubuntuforums by Andy Meier:

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.

share|improve this answer
if you s/escape/Escape then this is all good. – oadams May 10 '12 at 5:20
Yep, needs s/escape/Escape for me on Fedora 23. Can the answer be edited? – markwatson Nov 23 '15 at 18:20

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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.