Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

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.