Getting The Most From Sublime Text 3

Using a text editor as an IDE sounds antediluvian, right? Well, then you probably haven’t tried Sublime Text. With it’s modern UI, superb performance, and fantastic feature set, it’s a must-have whether you’re a developer or a writer. Here are a few tips on how to get the most out of the best text editor to come along in the last decade.

Another Text Editor? Really?

Listen, I know what you’re probably thinking right now.

When telemarketers call.
Ask him if it comes with a free blender. Tell him the other guy offered you a free blender.

You may think you don’t need it; you’re already a power user of the best text editor for you, so why bother? But there’s a reason Sublime Text  has exploded in popularity in recent years as a best-in-class text-editor-ide hybrid; even beating out such desktop institutions as TextPad, TextMate, UltraEdit and Notepad++.

I first stumbled across Sublime Text while looking for a replacement for my favorite text editor, which I used almost exclusively for my HTML, CSS, JavaScript and Perl development. While I loved the beauty and simplicity of TextPad – I’ve been an acolyte for them for well over a decade – I had needs that weren’t getting fulfilled; namely, code folding, auto-complete and a dark theme. Sure, I could get most of those in an IDE – and I do regularly use Visual Studio and various flavors of Eclipse for my .NET and Java development, respectively – still, I saw no reason those feature couldn’t be included in my text editor.

Among the text editors that offered some or all of these features (like Komodo, which has grown up quite a bit in recent years), I found their implementations lacking. In Sublime Text, I found my expectations not just realized, but exceeded.

Some Assembly Required

Start by downloading and installing Sublime Text 3. The 3065 beta is the most recent version available as I write this. While you can evaluate Sublime Text for free as long as you like- there’s a pesky nag screen inviting you to register every 100 saves or so – I would highly recommend buying a license if you intend to use it long term. Don’t be afraid to buy it now, the license works for Sublime Text 2, and will work for the full version of Sublime Text 3 when it’s finally released.

Requires less assembly than the Ikea Throne
Requires less assembly than the Ikea Iron Throne

So why am I recommending version 3 when it’s still in beta?  Because many of the plugins I need and use have already dropped support for version 2 and are now only available to download for version 3.  Not only is it that stable, but by the time you read this it might already be out of beta.

I should note here that I’m using Sublime on Windows 7. It’s available for Mac and Linux, but some of the key mappings I reference might not be the same on your OS;  you should be able to figure out the right key mappings easily.

Potential Proxy Settings Needed

Wendy Harris, aka Proxy, daughter of Calculator, previous caretaker of Titan Tower!
Wendy Harris, aka Proxy, daughter of Calculator, previous caretaker of Titan Tower!

If you’re behind a corporate firewall, setting up your proxy is the first order of business.  If you’ve already installed and configured Cntlm using the instructions from my previous post, it’s a simple thing to do.  If you haven’t, go do that first, then pick back up here.

I’ll wait.

Okay, now that you have your local proxy running, open up Sublime Text and click on the Preferences menu and select the Settings – User menu item.

Sublime Text > Preferences > Settings - User
Sublime Text > Preferences > Settings – User

This will open your user settings file, which will likely be empty at first.  Settings are stored as JSON, so let’s add the following lines:

[code lang=”javascript”]
"http_proxy": "localhost:3128",
"https_proxy": "localhost:3128"

Where 3128 is the port number you set Cntlm to listen on.  Go ahead and save and close this file for now, but we’ll be coming back to it later.

Plugins and Plugin Management

It's not a perfect metaphor...oh, wait, it is!
It’s not a perfect metaphor…oh, wait, it is!

Sublime has a rich plugin platform, and a large community of contributors.  It can be difficult to wade through all the available plugins to find the ones that work for you, so here are a few that I find indispensable.

1. Package Control

The rich plugin platform is great, but Sublime Text does not (yet) provide a default plugin management utility. If you want to avoid the chaos implied in the photo above, I would suggest using William Bond’s Package Control plugin, as it has become a de facto tool for anyone publishing or consuming Sublime Text plugins.

The official website has easy to follow installation instructions, just make sure you use the right console command for your version of Sublime. Refer to the usage documentation for a comprehensive overview. The only command I’m going to cover here is Install Package.

Package Control is invoked via the Sublime Text Command Palette, which is accessed using Ctrl+Shift+p or from the menu bar via Tools > Command Palette. From the Command Palette, type the word install, and the Install Package command should show up, highlighted, at the top of the list. Press Enter and you are ready to find a plugin to install. Type the name of the plugin you want to install, select it from the list of matching options, and viola, the plugin is installed for you!

2. Sidebar Enhancements

The Sublime sidebar can be opened from the menu View > Sidebar > Show Sidebar. The sidebar shows you a list of project files and, optionally, a list of open files. Tito Bouzout has developed several great plugins available for Sublime Text, but one of my favorites is Sidebar Enhancements, which we can install via Package Control.

But wait! Before you install it, open some files and folders in Sublime Text and check out the default right-click options.  Then install the plugin. The difference will amaze you.

Sidebar Enhancement
The right-click menu after installing the Sidebar Enhancement plugin

With this plugin you can customize the Open with… context menu, and configure hot keys to open the current file in a browser. Combined that with an auto-refresh browser plugin (not included) and you have a pretty sweet development rig going on!

If you find these useful, I would also highly recommend SidbarFolders and SidebarGit, also by Señor Bouzout.

3. Soda Theme

If you’re like me, the color scheme of the application (which is different from syntax highlighting) will play a large role in how much I like using an application.  I wasn’t too excited about Sublime Texts’ built in theme, so I went hunting for another.

There are tons to choose from, but my theme of choice is the Soda Theme, by Ian Hill – which, if you are on a Mac, has the bonus of supporting Retina display.  This theme can also be installed via Package Control, which makes it that much more awesome.

Soda Dark Theme in all it’s glory!

In addition to both a Lite and Dark color scheme, you can also choose between alternate tab styles and sidebar folder icons. You can even download the syntax highlighting color scheme to go along with your theme.  Details on how to do that are on the Soda Theme project page.

I use the Soda Dark theme with the modified version of Monokai he provides. If you want to change how the theme looks for you, you can find the details how on his Theme Customisation page.

Ian also notes that in his screenshots he is using the Menlo font, which is a Mac OS font.  If you’d like to use a similar font on Windows, check out the Meslo font on GitHub. I like to use the Sublime Text default font on Windows. The important thing is to use a monospaced font that looks good to you.

How Many Pieces Of Flair Is Up To You

Sublime offers tremendous amounts of customization, so you can make it your own in so many different ways. Or not. It’s up to you.

You do want to express yourself, don't you?
You do want to express yourself, don’t you?

For example, I’m used to the Shift+Tab hotkey unindenting the current line or selection by one level, but that isn’t a default behavior in Sublime.

You can, however, turn on this behavior by adding a line to your User preferences, like this:

[code lang=”javascript”]
"shift_tab_unindent": true

If that’s not enough, you can modify your key bindings to create new hotkeys.

Rolling Your Own Build System

Out of the box, Sublime has built-in feature support for languages like JavaScript, Python and PHP. But there isn’t very much built in for Perl, which gives us the opportunity to explore some of the more advanced features Sublime has to offer when it comes to pretending to be an IDE.

Do not go where the path may lead, go instead where there is no path and leave a trail.

Build systems run external programs to process your project’s files and print captured output to the output panel. We can make our own build system with some simple JSON saved in our User packages folder with a .sublime-build extension.

You can find your User packages folder by selecting Browse Packages from the Preferences menu in Sublime Text. In the file explorer window that opens, double click the User folder.

Assuming you already have Perl installed and in your PATH, our Perl.sublime-build file would look like this:

[code lang=”javascript”]
"cmd": ["perl", "-w", "$file"],
"file_regex": ".* at (.*) line ([0-9]*)",
"selector": "source.perl"

Whenever we have a file Sublime recognizes as a Perl file in context, we can invoke the build process using the hot-key combination Ctrl+b. If Sublime Text can’t determine that our file is a Perl file, we can insist that it is by selecting Perl from the Tools > Build System menu.

All We Need Are Snippets

Rounding out our feature set discussion is Sublime Snippets. These serve the same purpose as TextPad Clip Libraries, of which I was quite the power user back in the day.

Edward Snippet Hands
A sequel about Edwards’ son titled Charlie Snippet Toes was planned but never made.

Constructed in XML, snippets are smart templates of text. Aware of the context of their usage, they can save you tediously typing repetitious fragments of code. They are easily parameterized and simple to edit.

Below is an example snippet to read a file into a scalar in Per:

[code lang=”xml”]
<content><![CDATA[open(${1:FILE}, "$2");
flock (FILE, LOCK_SH);
my \$${3:file} = join("", <$1>);

<description>Read File To Scalar</description>

Note that the dollar sign ($) is used in a snippet as a placeholder for a parameterization, so if your snippet includes literal dollar signs (and in Perl they often will) then you’ll need to escape them using the backslash (\).

Save your snippets in a folder or subfolder of your User packages folder, and let the time savings begin!

Keeping Things In Sync

If, like me, you use Sublime on multiple computers, you probably want to keep your user defined content the same on each computer.

To keep my settings in sync across my multiple devices, I created a project on GitHub named Sukona (which is suppose to be Japanese for Sublime, but since I don’t actually speak Japanese, I’ll have to take the word of Google Translate). Feel free to check it out and use whatever you find useful there.

Sublime Is Limitless

There is so much more to Sublime Text that I don’t have the time or room to cover here – like making your own macros, syntax definitions or plugins – all of which makes Sublime Text a clear winner as a multi-purpose text editor. As Immanuel Kant said:

“Whereas the beautiful is limited, the sublime is limitless…”.

Bradley Cooper in Limitless
Drugs? No! What makes you think I’m on drugs?


Leave a Reply

Your email address will not be published. Required fields are marked *