Two of my favorite commands in Sublime Text are
lower_case. I’ve remapped
<Caps Lock> to
<Ctrl>, so if I have to type
SOME_LONG_CONSTANT_IN_SCREAMING_SNAKE_CASE, I can type it all out in lower case and press
Now I’d like the same thing for title case. I’d like to highlight some text, and type
super+k, super+t and have it all titleized.
Find the Sublime command
I don’t know if Sublime has this function, so I open up the help menu and search
'title case'. A command is available under
Edit > Convert Case > Title Case.
To find the internal command name for that function, open up the console (ctrl+`) and type this to tell Sublime to log every command it receives:
Title Case in the
Edit menu, and it will show up in the Sublime console.
Create a keyboard shortcut
Now we know that the command name is
title_case (who knew?), we can create a keyboard shortcut for it. Open up the menu
Sublime Text > Preferences > Key Bindings — User and add an entry:
This key combo is a little different. If you pass an array to the
"keys" key like that, it means to release the keys between presses. So you hold
super, press and release
k, then press and release
t. It’s common in Sublime to prefix keyboard shortcuts with
super+k for commands that are higher level or less commonly used.
If you want to use the more common pattern of pressing all keys at once, you can see many examples in
Sublime Text > Preferences > Key Bindings — Default. Here is one example:
Pass arguments to a command
I immediately added a second shortcut for toggling word wrap:
If you need to pass arguments to a command, that’s how it’s done.
Create a shortcut to add shortcuts
We know how to add shortcuts—let’s make it as easy as possible to add new ones. Open the console again, make sure Sublime is logging commands, then open the
Key Bindings — User file. This is what is logged:
open_file is the command, and the the rest are the args. Put that into a shortcut:
Now when I press
super-k, s, the user shortcuts file opens. You can pick a shortcut that makes sense to you.
Sublime is cool because it’s easy to hook into the editor to customize it. Use your new power to automate your workflow. Any time you feel the pain of doing something with the mouse, consider creating a keyboard shortcut.