3

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!

2 Answers 2

3

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"

3
  • 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, 2012 at 13:41
  • @dotancohen you would have to delegate to a bash script to do that
    – jsj
    Oct 26, 2012 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, 2012 at 13:49
1

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

:s/\vfalse|null|true|access|add|as|asc|begin|by|check|cluster|column|compress|connect|current|cursor|decimal|default|desc|else|elsif|end|exception|exclusive|file|for|from|function|group|having|identified|if|immediate|increment|index|initial|into|is|level|loop|maxextents|mode|modify|nocompress|nowait|of|offline|on|online|start|successful|synonym|table|then|to|trigger|uid|unique|user|validate|values|view|whenever|where|with|option|order|pctfree|privileges|procedure|public|resource|return|row|rowlabel|rownum|rows|session|share|size|smallint|type|using|not|and|or|in|any|some|all|between|exists|like|escape|union|intersect|minus|prior|distinct|sysdate|out|alter|analyze|audit|comment|commit|create|delete|drop|execute|explain|grant|insert|lock|noaudit|rename|revoke|rollback|savepoint|select|set|truncate|update|boolean|char|character|date|float|integer|long|mlslabel|number|raw|rowid|varchar|varchar2|varray/\U\0/g
8
  • 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, 2012 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, 2012 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, 2012 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, 2012 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, 2012 at 14:43

You must log in to answer this question.

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