Sublime Text for Front End Developers

The following is a guest post by Wes Bos. Wes has been writing about Sublime Text and all the great stuff it brings to code editing for a while now. He has a new book and video package out now: Sublime Text Power User. I met him at a conference recently and saw his talk on Sublime Text. The conference was buzzing about it. Newbie's jaws were dropped and old pro's learned new tricks. Here, Wes is going to share some of best stuff as it relates to front enders like us.

With Sublime Text being one of today's hottest editors for web development, it's important to know the ins and outs of the editor as it relates to front end development. Rather than being a step by step guide on Sublime Text, this post is filled with hot tips, tricks and packages that will make you amazing with Sublime Text.

Syntax Highlighters

It's almost 2015 and a ton has changed in the last few years - CSS has exploded with new features, JavaScript has introduced new functionality and syntax and we have a handful of new languages that compile into HTML, CSS or JavaScript. The syntax highlighters that come with Sublime are old, and even unavailable for some languages.

The following packages will allow for the best possible syntax highlighting. Even if you already have syntax highlighters for all of your languages - give this a read as you may wish to change a few of them.

The JavaScript Next syntax highlighter provides better code highlighting than the default JavaScript highlighter as well as support for ECMAScript 6 features such as modules, succinct methods, arrow functions, classes, generators, and accessors (ES5).

CSS3 provides highlighting for every CSS3 feature in the spec. That is everything new as well as things that are yet to be implemented. This should totally replace any existing CSS syntax highlighting that you have.

Sass users should install the SCSS package. Heads up - it's a common mistake to search and install the Sass when you really aren't writing the Sass syntax, but the Scss syntax - make sure you have the right one enabled so that all other packages, like Emmet, continue to work properly.

Of course there are are also Stylus and LESS packages available if they are your CSS weapon of choice.

Write Coffeescript? Make sure you have the Better-Coffeescript package installed. It's important to grab the better-coffeescript package as the regular CoffeeScript package is no longer maintained. There is also a Typescript Package those in that camp.

The Haml package extends the default Haml package to include nested languages such as JS, CSS, Sass, etc, so you can maintain both your highlighting and snippets. The Slim and Jade packages provide much needed highlighting to these newish markup languages.

Packages and Plugins

Sublime owes much of its popularity to the endless supply of interesting and helpful packages that the community has created. If you are new to Sublime, you can add and manage your packages with Package Control.

While we could sit around all day and talk about the best Sublime Packages, and I hope you do in the comments, these are a handful of must-have packages for a front end developer working with HTML, CSS and JavaScript.

Color Highlighter

When working with colors in a stylesheet - it's helpful to have some sort of visual aid showing you the actual color. Color Highlighter will scan your stylesheet and color your color name, hex code or RGBA by filling in the background with that color. There are options to underline with the color or display it as a circle in the gutter.

Recently, support for Sass, LESS, and Stylus variables have been added, which makes this tool ready for almost any workflow!

Emmet

Almost everyone already knows about Emmet and many have been using it since the Zen Coding days. However, I've found many developers are missing out on some of the powerful features of Emmet.

HTML

Emmet is great for writing HTML very quickly. Simply type the CSS selector for the markup you wish to have and hit tab. Use Jade, Slim or Haml? Emmet works with those markup languages too!

This can be as simple or as complicated as you want. Here are a few examples — be sure to check out the cheat sheet for all the possible ways to use Emmet with HTML.

`element` + `tab` creates that element and puts your cursor inside:

`span` + `tab` → <span></span>

`p` + `tab` → <p></p>

`element.className` or `element#ID` + `tab` creates that element with the associated class(es) or ID

`span.hello` + `tab` → <span class="hello"></span>

`p.odd.warning` + `tab` → <p class="odd warning"></p>

`div#contact` + `tab` → <div id="contact"></div>

`element>childElement` + `tab` creates nested elements

`ul>li` + `tab` → <ul><li></li></ul>

`p>span` + `tab` → <p><span></span></p>

`[element*5]` + `tab` creates that element times the number

`p.hello*2` + `tab` → <p class="hello"></p><p class="hello"></p>

You can also use the $ as a placeholder for the increment. Use $$ for a leading zero.

CSS

Learning Emmet for CSS is one the the better investments an front end developer can make. Not only does it speed you up, but it cuts down on the silly mistakes we all make.

Emmet for CSS works by typing the approximate CSS property/value that you want. There are no snippets, Emmet works on something called fuzzy matching which takes a best guess based on what you have inputted.

posrel → position: relative;

posab → position: absolute;

fl → float:

fr → float: right;

db → display: block;

dib → display: inline-block;

tdn → text-decoration: none;

c → color: #

w → width:

w100 → width: 100px;

w100p → width: 100%;

p → padding:

p10 → padding: 10px;

p10p → padding: 10%;

bt1-s-red → border-top: 1px solid red;

You get the point - it's worth taking the time to re-train your brain to use these fuzzy matches rather than typing the entire property and value out.

Sublime Linter

Linting your code is an important step in the process. If you have never used a linter before, it's a code quality tool that checks for errors and bad practices, alerting you when you make them.

With Sublime Linter you can easily get real-time linting feedback for virtually any language. As front end developers, we should be linting our JavaScript and possibly our CSS. If you make a mistake, Sublime Linter will stick a flag in the gutter alerting you to the error.

Themes and Color Schemes

Still using the default Sublime theme and color scheme? It might be time to check out a few different ones. There are two parts to changing the color of Sublime — a color scheme changes the color of your code syntax highlighting while a theme changes the color of the editor chrome such as the tabs, sidebar and command palette.

As of the latest build of Sublime Text 3, we now have the ability to put specific icons in the sidebar.

Whether you like light or dark, there is bound to be a theme that you like. Here are a few popular ones:

Solarized Dark

Solarized is a fantastic theme that offers a light counterpart as well. It's available in almost every editor and has become a beloved standard by many top developers.

Cobalt2

This is my own theme that has been a tweaked and refined over the last 5 years. It's based on the original Cobalt theme and has many improvements with an emphasis on being easy on the eyes with crisp and clear contrast.

Seti UI

A new theme on the scene, this is a very dark theme that offers chunky blue pops of color throughout.

GoTo anything

If you are coming from another editor such as Coda, Textmate or Dreamweaver, you probably rely on the sidebar to navigate around your files. Sublime introduced the concept of GoTo anything. At its simplest you can use it to open any file in your open folder or project. Just hit ⌘ (Ctrl on Windows) + p and it will open a list where you can start to type the name of your file. This dropdown supports fuzzy matching so you don't have to worry about spelling it exactly right, or even specifying which folder it is in.

Once comfortable with that, GoTo anything support line numbers of files jquery.js:205, column numbers jquery.js:205:15 as well as something called symbolsjquery.js@ajax which allow you to quickly jump to functions, methods or selectors.

What's your favorite?

Sublime Text is just packed full of handy features and packages. Enough to fill a book!

I installed the CSS3 package (https://github.com/y0ssar1an/CSS3/), and the message that its author has written stated that Emmet should be removed, as its CSS shortcuts is “often quite outdated, and it’s completions completely drown out the completions in this plugin.”

That might be a bitter pill to swallow for some developers who rely heavily on Emmet.

I do not know about PC or other FTP software but Transmit on Mac works nicely with Sublime Text. Just double click on the file in Transmit, it opens up in ST for editing, make changes and hit Cmd+S. The updated file gets automatically uploaded to the server.

Because the stability of a JavaScript driven coding environment is still not as stable as a native application, just like the native app vs. a wrapped web-app performance. Not only that, why would you use something else if it does exactly the same? If you’re used to one thing, there’s no point reinventing the wheel on yourself. If you mean as alternative to price differences, well, obviously Atom is open source whereas ST3 isn’t and that might put you off ST3. Though, it’s not about the tools, it’s the person who uses them! ;)

I would highly recommend Git and GitGutter packages for Sublime Text. The first allows you to do most git-related actions without having to leave the editor through the go-to-anything menu (adding, committing, pushing, diffing, viewing status etc etc), the second shows you the git diff from the current HEAD in the gutter, so you always know what you added/changed/removed.

There are options to underline with the color or display it as a circle in the gutter.

Unfortunately I can’t get the colored circle to be displayed in the gutter. Does anyone know why this is? The ColorHighlighter settings seem to be right ("icons": true) so probaly it is some (ST3) setting which isn’t set correctly.

As the (admittedly negligent) maintainer of the Sass ST2/3 package, I would love to implement full support for SCSS, along with a host of other improvements. (It’ll probably require a full refactor, plus lots of testing). The current package has been in lockdown mode as one of the last pull requests I merged in broke things pretty badly, and I couldn’t risk that happening again.

Nice article! Emmet is definitely one of the first packages I install when setting up a new Sublime Text install. I’ll also have to give Sublime Linter a shot.

A couple of packages that I use additionally are:

GitGutter – which gives you nice gutter icons to let you know whether you’ve made changes to a file. This keeps me in the text-editor instead of checking git diff in Terminal to see if any changes have been made.

SidebarEnhancements – gives you a bunch of additional file and folder operations such as new file, duplicate file, open with finder, etc for your sidebar.

I’ve tried using sublime over the past few years and could never quite get my workflow dialed into it. I always felt like I had to tweak and hack every feature I wanted to sort of get the functionality I wanted. It just never seems very solid though. I felt like the community plugins were so disjointed and inconsistent in their implementations.

I don’t mean to totally knock Sublime. I do appreciate how fast it is and I think it looks really nice. And if it works great for you, then awesome!

I’m currently using phpstorm and would highly recommend it to anyone looking to check out a different editor. Like Sublime, it has tons of plugins that fill practically every need I’ve ever had in the app, but they integrate into the app a lot tighter. Jet Brains makes most of the core plugins as well so they are very solid and just work. In general it just does a lot of super smart things with code, the debugger is awesome and using git couldn’t be easier.

Hey all, I’ve bought Sublime Text 3, used it in the past.
* It’s a great product.
* It’s very fast
* It’s perfect for people moving from VI or VIM
However, in my case, it was less useful than what I was already using. There are some file types that I still like to use Sublime Text for, as it can handle some files well; eg. Template files.
I have stuck with Jet Brains: phpStorm. They also have WebStorm.
* helps debug from IDE
* jump to functions
* search for a file or class
* code inspection, so you know if a typo exists before running code
* sass, less, git, …
* plenty of plugins
I still cannot find a better IDE, the only other one that is similar is NetBeans & Eclipse however they are bloated and too slow for my liking… so I just pay for phpStorm.

Hope that helps you all. I know how time draining it can be to look for a good IDE. Cheerioooo

I’m using Coda 2, but Sublime seems to be more intuitive. But Coda has ftp built in, which ftp your file as you save it.
Any OSX standalone FTP tool that can serve me with the same thing? Upload as I save a file in Sumblime?

For SCSS highlighting, I’ve long been using this package rather than the SCSS one you mention. The author has done a lot of work supporting the most recent syntax more thoroughly and coverage is much better. From the same author there is also a javascript highlighting package comparable to Javascript Next https://github.com/P233/Syntax-highlighting-for-Sass

Nice post about emmet, some things I did not know about it.
I’m personally using ITG theme for it’s eye relax feeling. Some of plugins worth mention – Favorite files and if you’re working on Bootstrap/Foundation Framework there’re some snippets so you can make components with just few clicks.