I’m in the middle of taking the “Up and Running with Sublime Text 2” course on Lynda.com with Kevin Yank and thought it would be a good idea to jot down (as a tutorial) the major areas of what I think is important. All too often, I take a course and have trouble retaining what I’ve learned. Of course, I know where to look back when I need a tidbit of knowledge, but perhaps recording things here is a better, more centralized, location.
I want to mention a quick, yet interesting, coincidence here – Kevin Yank was the author of a PHP book I purchased way back somewhere around 2000. Boy, it’s been a long time. Funny how things come full circle. I still have that book.
Sublime Text seems to be the text editor of choice these days for designers, developers and hardcore coders alike. I have sort of an “against the mainstream” type of personality, so I’m continuously on the hunt for alternatives, but in this instance, I can’t help but to get involved with Sublime. Even though there are very qualified editors in the market, when I see instructor after instructor use Sublime, I think it would be in my best interest to understand and use the industry standard. By the way, Kevin Yank has a great post written about what setup he likes for his install of Sublime. Check it out if you want a behind the scenes glimpse of how a pro operates.
Left Gutter – Line numbers as well as arrows for expanding and collapsing sections of code. Examples of code that can collapse is functions, loops, if statements, commented areas and more. Also on that side are tab columns which offer a much more clear picture of where your code is tabbed. Very nice feature.
Bottom Status Bar – Shows line and column number of current placement of cursor. This status bar also shows your file’s current indent settings. You may edit those settings for future coding by simply clicking the current settings text in the status bar. Lastly, over to the right, Sublime displays the coding language it thinks your open file is written in and will highlight the syntax accordingly. To alter that highlighting, simply (again) click on the current text that’s shown in that status bar and a menu will appear.
Right Column – A mini map of your code is displayed. This map shows your code in its entirety and allows for simplified scrolling through long documents.
Keyboard Shortcuts and Helpful Actions
Windows / Mac
Ctrl+N or Command+N – Create new file. Opens new tab called “untitled.” You may also choose “New File” from the File menu.
Ctrl+O or Command+O – Opens existing file. You may also choose “Open File” from the File menu. You can also drag your file over into the application window (while Sublime is running) or simply drag your file over to your desktop icon (while Sublime is not running). That’s a fun one.
Ctrl+W or Command+W – Closes existing file. You may also choose “Close File” from the File menu.
Ctrl+Shift+T or Shift+Command+T – Re-opens most recently closed file. You can choose to do this via the File menu by clicking on “Open Recent.”
Toggling Between Tabs
Alt+ or Command+(Number On the Keyboard) – Choose the number on your keyboard that corresponds to the placement of the tab you’d like to work on. Toggles between tabs easily if you’ve got fewer than ten tabs open.
Ctrl+Page Up / Page Down or Option+Command+Left/Right Arrow – Toggles between open tabs sequentially.
Ctrl+Tab – Toggles between the most used tabs. Great for saving time focusing only on “working” files.
Ctrl+P or Command+P – Displays list of open files as a drop-down. It’s also searchable.
All of these commands can be found under the “Goto” menu.
Cool Editing Features
Line Endings – You can choose what types of line endings you want your file to include by clicking “View > Line Ending” from the top menu bar.
Spell Check – You can have your document spell checked by Sublime by choosing “View > Spell Check” from the top menu. Misspelled words will appear in your code with a red underline. To be presented with suggestions for the correct spelling, simply right click on the misspelled word.
Indenting – Ctrl+] or Command+] (those are right brackets) to indent blocks of code. To unindent, simply choose the other square bracket. For multiple indents, keep clicking the square bracket. If you’ve unindented too far, click “Edit > Line > Reindent” and Sublime will indent how it sees fit.
Bracket Matching – Sublime identifies opening and closing brackets. Use Ctrl+M to jump between them with your cursor. Works for brackets, parenthesis and curly braces. To take advantage of this option from the top menu, click “Goto > Jump To Matching Bracket.”
Split Windows & Layouts
Sublime Text has some really nice features for splitting up the windows you’re working in. If you have multiple files open, you can click “View > Layout” from the top menu bar and choose what you want your layout to look like. It you want to toggle between your working files, you can use the Ctrl+1, 2, 3 and so on keyboard shortcuts. To get your files in the new panes once you choose your layout, simply drag each tab where you want. If you want to go back to a single window, no need to drag your tabs again. You only need to choose the single window option from the top menu.
If you’d like to work on one file, multiple places simultaneously, you can do that. Go to the top menu and choose “File > New View Into File” and your working file will be duplicated as another tab. Drag that tab to another window and begin editing. You’ll notice that any change from one view will instantly change the other view as well.
Opening Folders & Working in Projects
If you’d like to open a folder in Sublime, simply drag the folder into the workspace. You’ll notice the left bar opens with your folder structure available. Alternatively, you can also click “File > Open Folder” from the top menu.
If you’d like to save the folder as a project, you can click “Project > Save Project As” from the top menu and you’re project will be saved. If you open multiple projects, you can switch between them by clicking “Project > Switch Project in Window” (Ctrl+Alt+P or Ctrl+Command+P). Remember that all changes will remain and files will be saved when switching through projects.
Finding & Replacing
Sublime’s find and replace features are really good. I’m sure it’s one of their best selling points. Below, I’m going to list out some keyboard shortcuts and after that, I’ll offer up some commentary on a few.
Find – Ctrl+F or Command+F – Searches current file. Utilize the “Enter” key to progress through the search results.
Note: When you perform a search, option buttons appear to the left of the search bar at the bottom. Those option button are: Regular Expression (Alt+R), Case Sensitive (Alt+C), Whole Word (Alt+W), Reverse Direction, Wrap, In Selection and Highlight Matches.
The buttons on the right of the search bar are: Find, Find Prev and Find All.
To close the search box, click “Esc” on your keyboard.
Find Next – F3
Find Previous – Shift+F3
Incremental Find – Ctrl+I or Command+I – Searches and after hitting “Enter” you’re cursor is left at your first result. If you click the “Esc” key while using Incremental Find, your cursor will return to its original location.
Replace – Ctrl+H or Option+Command+F – Replaces text. You also have the ability to keep your text case if you use the “Preserve Case” (Alt-A) button down to the left of the “Replace With” field.
Replace Next – Ctrl+Shift+H
Quick Find – Ctrl+F3
Quick Find All – Alt+F3
Quick Add Next – Ctrl+D
Quick Skip Next – Ctrl+K, Ctrl+D
Use Selection For Find – Ctrl+E
Use Selection For Replace – Ctrl+Shift+E
Find in Files – Ctrl+Shift+F – One of the coolest features of Sublime’s search (in my opinion) is the ability to search across files. If you use the shortcut I listed above, you can search within your entire project. The results are shown in their own tab. As you browse your results, you can double click on your results to land exactly where your search result is within its file. I first saw Carrie Dils performing this type of search during her Genesis class and this feature by itself is part of the reason I decided to take Kevin Yank’s course.
If you don’t like the separate tab option, you can choose to have your results shown in their own box below your files. Same thing there – just click the results in that box and you will land on your desired code. To jump through your search results, simply press F4 on your keyboard.
Personally, I think these search features alone warrant the money paid for the registered version of Sublime Text.
PS – Check out this post by CSS Tricks to learn some great features Sublime Text offers.
Please check out my further posts on how to work with Sublime Text by clicking on the Dev Tools category.