From what I’ve heard and read, programmers love to code quickly. If you’ve ever had the chance to watch an experienced programmer at work, you know what I’m talking about. Even tutorials on Youtube sometimes include someone who’s flying around at the speed of sound. That style isn’t great for teaching, but it sure is good for getting things done.
Sublime has many features to assist in speeding up the editing of files. Speeding up editing means speeding up work – and that means finishing projects with the most efficiency possible.
In this post, I’m going to go over some techniques programmers use to code like it’s, well, their jobs. It’s good stuff.
Selection
I’m going to quickly discuss the “Selection” menu in Sublime Text. There are many handy tools you can use to speed up your selecting of text and code in your files. I’ll show the keyboard shortcut and then explain what each does.
Ctrl+A – Select everything in the file.
Ctrl+D – Select the word your cursor is on.
Ctrl+L – Select the line your cursor is on.
Ctrl+Shift+A – First, selects the contents of a tag your cursor is in. If you continue hitting the “A,” your selection will expand to include the tags themselves, then their containing tags and eventually the entire page of code.
Ctrl+Shift+M – Selects the contents of a set of brackets. If you continue to hit the “M” key, your selection will expand to include the brackets themselves, their parents, and onward. Brackets are considered parentheses, square brackets and curly braces.
Ctrl+Shift+J – Selects the indented area your cursor resides (and indented children). If you start at a multiple indented piece of code and continue to hit the “J” key, your selection will expand upward to cover the each parent. So, if you start at the furthest child indentation, it will step up to cover each parent, but if you start at the highest parent, you will select all children at once.
Ctrl+Shift+Space – Selects everything within a certain scope. If you have colored code in Sublime and your cursor is residing in some of it, you will select all the colored code in that scope.
Expand Selection to Paragraph – Select the paragraph your cursor is in. Paragraphs are considered blocks of code that have an empty line before them and after them. They needn’t be real paragraphs. Currently, there is no keyboard shortcut assigned to this, but you can get there by “Selection > Expand Selection to Paragraph” in the top menu.
Alt+Left or Right Arrow – Instead of moving one letter at a time, your cursor moves one word at a time.
Alt+Shift+Left or Right Arrow – Instead of only moving one word at a time, your cursor selects each word you move to, progressively.
Transposing & Swapping
Ctrl+T – If you place your cursor between two letters, you can transpose them with each other. They will simply switch positions.
Ctrl+Shift+Up or Down Arrow – If you would like to move an entire line up or down through your code, use these keys. Also works for any chunk of code you highlight. You can move the whole chunk.
Bookmarking
Under the “Goto” menu, you can find a Bookmarks side menu. I’ll go over some bookmarking features below.
Ctrl+F2 – This will create a bookmark (small arrow) in the left gutter of the line your cursor resides. If you are on a laptop like I am, and you have to click a “Fn” key to select your “F” keys, you will need to hit Ctrl+Fn+F2. It works just the same.
F2 – This will move you to your next bookmark.
Shift+F2 – This will move you to your previous bookmark.
Ctrl+Shift+F2 – This will clear all your bookmarks.
Alt+F2 – This will select all your bookmarks.
Just as a side note, once you create a bookmark, the line it’s on will appear in the “Goto > Bookmarks” menu. Clearing them will make them disappear from that menu.
Goto Anything
Ctrl+P – Will pull up the Goto Anything menu. From there, you can search files in your project. If you want to just browse each file in the menu, hit the up and down arrows.
# – If you type the # symbol while the Goto Anything menu is open, you will enter fuzzy matching mode. You should see many items appear in Various rows. You can either click on one of those items or start typing any letters in the text you would like to find. If the word “dog” appeared in your code somewhere, you would simply need to type “#dg.” If you wanted to find “bird,” you would simply need to type “#bd.”
Partial File Name+# – If you have a project open and would like to search a specific file for something, you would only need to type a partial file name (until that file shows in your search bar) in the Goto Anything menu and then the # symbol.
:+Line Number – If you would like to search for a specific line number in the GotoAnything menu, simply type a “:” and then the line number and you will jump right to that line number.
Partial File Name+:+Line Number – If you’d like to take a glance at a line in a file that’s not open, in the Goto Anything menu, type the partial file name and then “:” and the line number. You would jump right to that line without opening the file.
Command Palette
Ctrl+Shift+P – This palette offer a list of all available commands. Accepts fuzzy matching for searches of those commands. Basically, if you would like to quickly search for a command, open this menu and start typing what you think the name of it is. Your choices will be filtered as you type and the closer you get, the clearer your choices will become.
Multiple Selection
If you’re reading this post, you’ve most likely seen the multiple selection feature of Sublime Text. If you’re like me, your mouth probably dropped open when you saw it. It’s one of those really, really neat things to be able to do.
Ctrl – To make multiple selections with your cursor, simply place your cursor where you would like your first selection and then hold down the “Ctrl” key. Then, click each next spot you would like to select. When you are finished, you should have multiple blinking cursors.
Ctrl+Alt+Up or Down – Instead of clicking each area you’d like your additional cursor to be, you can simply click the first one again and then click the Ctrl+Alt+Up or Down keys to trail your cursor in either direction. When you’re finished, you should have the same as above – multiple blinking cursors.
Ctrl+Shift+L – If you’d like a different way to make multiple selections, you could highlight the lines you’d like to make your selections in and then split those lines. Once your lines are highlighted, click “Ctrl+Shift+L” and you’ll see your cursor blinking at the end of each line. Just hit the left arrow to move your cursors to the beginning of each line and then the space bar to the spot you’d like to make your edits. You may also click the “Alt+Left or Right Arrows” to jump by word.
—–
That’s all I’m going to write for this post. There were actually a few more sections that I wanted to cover, but I’m beginning to realize that in order to keep the same level of detail, I’m going to have to write separate posts for each section. I”ll leave that for another day.
If everyone wrote posts like this, my life sure would be a lot easier.
Thank you Kim! You can check out our other posts about Sublime Text in our Dev Tools category.