Super User is a question and answer site for computer enthusiasts and power users. 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

Is there any way to configure the keyboard so that pressing ESC will also cancel the Capslock feature, if Capslock is enabled? I specifically use Kubuntu Linux with ESC and Caps keys switched (VIM user) but my coding SQL statements code practices dictate the use of CAPS for SQL keywords. I would prefer a general Linux / X solution but a KDE-specific solution is alright as well.

Thank you!

share|improve this question
up vote 3 down vote accepted

An X-Windows specific solution would be to use xbindkeys

  1. Install xbindkeys from your distro's repository.
  2. Create a config file .xbindkeysrc in your home directory
  3. Run xbindkeys -k from the terminal. This should open a GUI window. With that window focused press the key you wish to bind.
  4. Copy the code snippet relating to that key from the terminal
  5. Paste it into your .xbindkeysrc
  6. Replace the "command schema" with a command to run when you press that key.

In your case you would need to create a script to turn caps lock off and then generate a real escape key event (using crikey to send XTest signals perhaps)

You can check whether your caps-lock is on using xset q | grep "LED mask"

share|improve this answer
Thank you trideceth, that is a great answer. I don't see from casual googling that there exist either an if flow control in xbindkeys, nor a "Disable Capslock" code that would have no effect if Capslock is not set. I'll keep looking and update if I find either of those. – dotancohen Oct 26 '12 at 13:41
@dotancohen you would have to delegate to a bash script to do that – jsj Oct 26 '12 at 13:42
Thanks, I see your edit that even mentions how to do that. I'm fiddling with it now, thank you! – dotancohen Oct 26 '12 at 13:49

What about a dumb, short-sighted and brutal Vim-specific solution?

share|improve this answer
That might work! It's not finding anything as posted, I'll google how to get the regex to work and I'll post back. Thanks, Romain! – dotancohen Oct 26 '12 at 13:35
Forgot the \v at the beginning of the search pattern. It works, now. But it is very brutal and very dumb. xbindkeys sounds better. – romainl Oct 26 '12 at 14:01
Yes, it is too brutal and I've had to trim it down quite a bit. I'm now trying to get it to only match whole words but VIM regex is a bit different than PCRE. However, it is a great tool to have for the common one-liner SQL keywords such as INSERT, INTO, TABLE, WHERE, SELECT, DELETE, FROM, LIMIT, ORDER, BY, ASC, DESC, SET, UPDATE. As soon as I've got this whole-word issue sorted out I'm mapping it to leader-s. Thanks! – dotancohen Oct 26 '12 at 14:20
The following form is perfect: :s/\v<where>|<select>|<delete>|<from>/\U\0/g. Thanks! As is obvious, I will select trideceth's solution as it does answer the question and it much broader is scope. But I do love this trick and I see this becoming a common tool in my box. Thank you Romain! – dotancohen Oct 26 '12 at 14:36
De nada. Regular expressions are at the heart of Vim. It's sometimes a bit tricky to come up with the right pattern but once you have it it's so simple to create a mapping for later reuse… I ♥ Vim. – romainl Oct 26 '12 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .