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

If I have Caps Lock on by accident and type "lIKE THIS", is there a keyboard shortcut to transform it into "Like this"?

I'm familiar with Ctrl+KL to lowercase a selection, but I"m looking to toggle the case of each selected character.

share|improve this question
up vote 1 down vote accepted

If you can't find a built in, I wanted to do try out writing a plugin with something more than a Hello World so here it is.

Under Tools -> New Plugin... you can create an empty file and paste this in. (Note that python is somewhat particular about white space so if you have any issues make sure the spacing is as I have it below).

import sublime, sublime_plugin

class CaseswapCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        region = self.view.sel()[0]
        str = self.view.substr(region)
        ans = ''.join([char.lower() if char.isupper() else char.upper() for char in str ])
        self.view.replace(edit, region, ans)

Then edit your key bindings and include something like this.

{ "keys": ["control+shift+m"], "command": "caseswap" }

I've only tested this in MacOSX.

share|improve this answer
Thanks! This is seriously nifty. – Thalecress Dec 10 '12 at 22:18

Sublime Text 2 has this functionality built in.

Go to Edit -> Convert Case -> Swap Case

You can add a keybinding by opening your user keybindings Preferences -> Key Bindings - User and input your desired keybinding like the one above

{ "keys": ["control+shift+m"], "command": "swap_case" }

share|improve this answer

You must log in to answer this question.

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