10 keyboard shortcuts to become a true Sublime Text ninja

Little ninjas on Sublime Text logo

In September I published a post about 10 Sublime Text shortcuts that every web developer should know. This month I want to get a bit deeper into the topic and introduce 10 shortcuts that some people may not be familiar with which will speed up your coding workflow towards ninja standards. Let’s dive right in…

Bookmarking

An essential part of coding is going back and forth between particular parts of your code. But remembering all the line numbers by hard is a big pain. Luckily, you don’t have to with the help of bookmarks. Use CMD+F2 to set as many bookmarks as you want. Then use F2 and SHIFT+F2 to jump back and forth between them.

Command + F2, Shift + F2

Joining and swapping lines

Although the operating system already offers pretty good editing techniques such as jumping to the beginning or end of a line, Sublime Text provides a few more to speed up the most common tweaks: If you want to join the following line with the current one without having to go through all the whitespace in between, just use CMD+J. If you want to swap these lines, use CMD+CTRL+ARROW KEY. Yay!

Command + J, Command + Ctrl + Arrow Keys

Multiple cursors

Have you ever had to do the same modification in multiple lines of code? Could you not imagine a more elegant way of doing this than going through each of the lines one by one? Multiple cursors to the rescue! CTRL+SHIFT+ARROW KEY will add another caret to the line above or below the current position. All subsequent commands will now be carried out simultaneously by all the cursors that you have created. This is going to save you so much time that from now on you can go home a bit earlier each day.

CTRL + SHIFT + ARROW KEYS

Add all occurrences of the selected text to the selection

Sometimes you want to partly modify a variable name or class name globally, but using the search & replace mode with a complicated regular expression seems too much work. The command CTRL+CMD+G is like an interactive advanced search & replace: It creates a new caret at each occurrence of the search string and lets you edit them all at once, like a little ninja army carrying out your instructions. In order to get rid of all the cursors, simply use “escape”.

CTRL + COMMAND + G

Closing current HTML tag

This one is especially useful for frontend developers writing tons of HTML each day. Unless you have something like the Tag package installed, you may have wondered how to close the HTML tag you are currently in. CMD+ALT+. will do just that, saving you a few seconds per day that you can now dedicate to become a super ninja at HTML coding by learning Emmet.

Command + Alt + Dot

Jump to matching brackets

When you’re writing code in a programming language like PHP or JavaScript you happen to be inside of loops, conditions, functions or other programming constructs all the time. And the probability with which you’ll find its corresponding opening and closing bracket with your naked eye is usually proportional to how deep your current line is nested in the code. By using CTRL+M however, you can move your cursor instantly there, and hitting it twice will take you to its opening/closing counterpart. Doesn’t that just blow you over?

CTRL + M

Keyboard scrolling

There are times when your mouse or touch device may be out of reach and you just want to scroll up or down a few lines without loosing the current cursor position. To accomplish this, use the arrow keys as usual, but in combination with CTRL+ALT+ARROWS. Congrats, you’re now scrolling like a ninja without taking your hands off the nunchuk, ehh… keyboard.

CTRL + ALT + ARROWS

Creating row layouts

In part one of this mini-series you learned how to create column layouts (CMD+ALT+2). Now let’s move on to a more advanced ninja move to see how good you can bend your fingers. In order to split your current window into two rows use this: CMD+ALT+SHIFT+2. Once you have mastered this move, try to guess how to get back to the 1-column-1-row layout?!

Command + Alt + Shift + 2

Open user settings

Sublime Text is extremely flexible, even to such an extent that it might scare away some users. In the next part of this mini-series we’ll go over the most common settings that people tend to customize in order to improve their workflow. In the meantime, you may want to go ahead and experiment a bit with your user settings (which override the default settings found under Preferences > Settings - Default. Here’s the last shortcut for today, CMD+,, which will take you there with no detour.

Command + Comma

Wrapping up

Becoming a real Sublime Text ninja takes a lot of time, patience and most importantly, practice. And that’s why you shouldn’t get discouraged when you can’t recall that mind-blowing key stroke the first time you wanna show off your newly acquired skills in front of a co-worker.

You have to internalize that stuff by repeating it every day, or pin a cheat sheet (see additional resource) on your office wall for a few weeks so they’re always within easy reach. While in the beginning it may be hard to resist the urge to use your mouse, it’s a lot more effective to not take your hands off the keyboard for every single action.

After a while, you won’t miss it anymore and perform everything directly with a few key strokes, something which is not only a great way to impress others (especially non-programmers), but also to save you a lot of time each day and to feel more confident in what you’re doing.

Additional resources