DEV Community

Cover image for My Top 10 Sublime Text Shortcuts
Sibusiso Dlamini
Sibusiso Dlamini

Posted on

My Top 10 Sublime Text Shortcuts

How much time has the shortcuts ctrl + c + ctrl + v saved you? If you could recall every line of code, every paragraph of text, every One Time Pin or URL that you copied and pasted instead of typing out, how much time would that add up to? And if more shortcuts existed that could turn a 30-minute task into 10 minutes, then surely that shortcut must be worth learning.

There are plenty of time-saving shortcuts, and I don't think people talk about them enough. The truth is most people never take it upon themselves to discover the shortcuts of an app or website that they regularly use, myself included. So in this post, I want to go over my favourite non-generic key-bindings that I can't live without.

tip💡

The key bindings in this list are ones that I have memorised after needing to use them many times. I didn't memorise them all at once, but I stumbled across one or two interesting ones in a blog or YouTube video. After using them a couple of times, it becomes difficult to forget. So if there is one thing that I would like you to take away, there is no need to memorise all the shortcuts but instead, pick one or two that you find most useful.

From this point on, I'll use the word key-binding instead of shortcut with reference to Sublime Text. I'm doing this to emphasise that key-bindings are settings on Sublime Text that can be changed. So if you don't like the specific key combination, you could change it to something that suits your typing style or how your fingers rest on the keyboard.

Without further ado, let's get straight into it!

1 - Moving lines of text up and down

Key binding: ctrl + shift + up or ctrl + shift + down

movinglines.gif

If you are someone who cuts and pastes code to change the order that statements execute, you might find this key-binding very useful. Instead of having to cut and paste it, you can simply move the lines up or down. Here is a short demo of how it works.

When I code, I like to place functions in a specific order as if I were adhering to a style guide. For example, I arrange my CSS code according to specificity. This key-binding lets me organise my code on the fly to make it easy to keep to a style guide. This key-binding is probably the one that I use the most. If there is a key-binding, I can't live without it's this one.

2 - Scrolling between lines

Keys binding: ctrl + up or ctr + down

This key-binding is just another way to scroll. The difference between using this and simply pressing the up or down keys is that it keeps your cursor in the same position as if you were using a mouse to scroll instead of moving the cursor.

A typical scenario of when this key-binding comes in handy is when I want to remember what a particular function does without losing the line/block of code that I am currently working on.

This key-binding isn't a game-changer for me, but it is nice to know if you don't like reaching for the mouse while coding.

3 - Selecting multiple occurrences of a word

key-binding: ctrl + d

duplicates.gif

This key-binding works as a great alternative to the find-and-replace shortcut.

To use this key-binding, you first have to select a sequence of characters, and then once you press ctrl + d it selects all the other appearances of the selected word. Here is a little demo of what that might look like, and hopefully, you can see the capabilities of this key-binding.

This key-binding is my most significant time-saver and is worth remembering.

4 - Jumping between files

Key bindings ctrl + p ****

This key-binding lets you search for a file and open it depending on the project folder. When used, Sublime Text will list all the files in the current project folder and you can scroll them, and you can preview them as you scroll. Only when you hit enter does sublime open the file that you have you selected like so...

lookingforfiles.gif

I tend to use this key binding a lot if I'm working on a web development project because the file structure can get very large, very quickly and I tend to forget where I put everything.

5 - Jumping between functions

Key binding: ctrl + p + @

This key binding is technically an extension of the last one. After hitting ctrl + p and type in the @ symbol, Sublime Text creates a list of all the functions written within the file that you currently have opened.

searchingthroughfunctions.gif

I try to avoid using large files but because of the way that I excessively use new lines to format my code. Realistically, the amount of lines of code becomes large more often than not. And more lines makes bug hunting that much more difficult. This search functionality helps me keep a top view of my code so that I never really forget where everything is written. I don't need to memorise exactly where everything is written but rather in which functions they are written in, which should be easier to remember if I name my functions effectively.

6 - Splitting windows

key-binding: alt + shift + number where number = { 1,2,3 or 4 }

This key-binding splits the code view of sublime-text into multiple columns.

splittingviews.gif

I've never split my windows into more than two because my laptop screen isn't wide enough to work practically with three or more panels side by side. Otherwise, I've found this key-binding useful when coding in HTML and CSS. It is convenient to look at the markup and the styling simultaneously so you can get a better idea of what you are currently working on.

When I'm working in a large file and don't want to lose the line of code that I'm working on, I'll open the same file twice, and each view will be at different sections in the code so I can work at the top and the bottom of the file instead of having to scroll repeatedly between two blocks of code.

7 - Focusing on different views

key-binding: ctrl + number where number = { 1, 2, 3, 4}

This key-binding lets you switch between the different views so that you can jump between them without using your mouse. e.g. If my HTML files is on the left column and CSS is on the right column ctrl + 1 will focus on the HTML file and ctrl + 2 will focus on the CSS file

Not only can you switch your cursor focus between tabs, but you can even move files between tabs if you hold down the shift key. In other words, if I'm focused on the first column with the HTML file and press ctrl + shift + 2, it will move my cursor into

8 - Toggle Zen mode

key-binding: ctrl + K, ctrl + B

This key-binding toggles the sidebar of Sublim Text so that you can make the most of your screen real estate. You might find that splitting your code view in half to make two columns makes your code feel cramped, so this will give you a little bit more space back.

togglezen.gif

Heads up, this is not average key-binding. You've got to press ctrl + K and then ctrl + B in quick succession. If you leave too much time between the key presses, then it simply builds or compiles the program that you currently have open.

9 - Build/compile/execute

key-binding: ctrl + B

This key-binding executes the build system, which depends on the file extension of the file that you have open. For example, Sublime knows to run .py files with the Python interpreter and compile .cpp files with GCC compiler etc.

Why I appreciate this key-binding is how simple it is to do with a single hand. Most code editors use ctrl + f9 or f10 to execute/run programs. Unless you've got long fingers, you would need to use two fingers to perform the shortcut. And if you have a laptop like mine where I've got to hold down the fn key to use the f1-12 keys, it becomes so easy to strain your hand. If you've got to put your hand through all that to use a shortcut then, it almost defeats the purpose of the shortcut. So I like that Sublime made this key-binding convenient.

10 - Conventional browser key bindings

key-bindings: ctrl + W , ctrl + T , ctrl + shift + T

Most browsers can open new tabs with ctrl + T, close tabs with ctrl + W and open previously closed tabs with ctrl + shift + T. Sublime makes your life easier by not changing these conventions, so you don't have to memorise new key-bindings for different apps.

Wrapping up

When I was younger, I discovered key-bindings and shortcuts by hitting every possible key combination I could think of until my screen went sideways or upside down. At which point I thought I had broken the computer. After a while, I realised that it was just a silly shortcut, and once I figured that, I was no longer afraid of pressing keys and clicking buttons that I was unfamiliar with - Except during startup. I don't go messing with that stuff. I'm brave but not that brave - I think, in general, people aren't as bold as I am to go pressing random keys. So I wrote this in the hopes that you might find something worth remembering. I swear by these shortcuts and hope they will serve you well.

As always, thanks for the read, and Happy Coding! 💻

Top comments (0)