An Editor You Will Regret You Haven’t Used Before (and Tips on Getting the Most out of it)
In a former article I slightly mentioned that if you were a JavaScript developer, Aptana Studio — with all its built-in JSLint support, intellisense, auto completion, task management features, and more… — was an excellent IDE for you.
But as time passed by, I realized that along with its good parts, I had some “very” serious issues with Aptana Studio‘s undesirable drawbacks. Here are to name two:
- Aptana was sucking up my RAM like an elephant: Its memory utilization was no less than 1 gigabyte. In fact, that’s not a really big problem, since I had plenty of free RAM. But regardless of the amount of RAM it used, as the project’s size increased so did Aptana‘s sluggishness.
- Every time I booted up the IDE, Aptana started indexing all the PHP files, and other resources. The project I was working on had plenty of PHP files. And I had to wait for the indexing operation’s completion to start doing anything reasonable. That indexing time was no less than ten minutes, and it felt like ages!
Aptana has taught me to continuously slow down, and live in a Zen-like patience.
I sticked with Aptana anyway, since it was the only IDE around that suited my JavaScript development needs… Or I thought it was, until I met Sublime Text 2
.
This week, I’ve completely transferred all my front-end development work to Sublime Text 2. After having used it thoroughly for more than 40 hours, I can confidently say that Sublime Text 2 is “the editor” for any JavaScript Engineer / Front-End Developer.
In this article, I’ll try to list a few features that make Sublime Text 2 uniquely stand out in the crowd. I’m sure you’ll learn more as you install and explore it further.
Blazing Fast
I believe Sublime Text 2 is one of the fastest, and one of the most incredible editors to come out in a long time! If you consider those big fat IDEs as monster trucks, Sublime Text 2 is a race car. Each has their own pros and cons. And I’ll prefer the race car
.
It is damn fast. So fast that sometimes you think a file opens and renders with full syntax highlighting before you click on it on the side bar. You have to see it, to believe it
. It’s the most responsive editor I’ve seen so far.
Cross-Platform Support
Sublime Text 2 is available for all major platforms:
- Linux,
- OS X,
- And Windows.
Extensibility
Sublime Text 2 is fully extensible with plug-ins. Plug-ins give Sublime Text 2 its flexibility, and power.
Sublime Text 2 plug-ins are Python scripts that re-use existing commands, or create new ones to build new features. You can use any of the available Application Commands, Window Commands, or Text Commands inside a Sublime Text 2 plug-in.
If you like to extend your development environment and make it behave the way you like you can look at the API reference and the plug-in reference — it’s really easy to get started.
Configuration Files
Almost anything you can imagine in Sublime Text 2 is configurable via editing JSON configuration files. Most of these configuration changes are reflected in real time: As soon as you edit and save the configuration file, the changes will be visible.
For instance, if you want to change the font family and font size you use, you can do it by clicking Preferences > File Settings – User and updating the JSON file you see with something like this:
{
"color_scheme": "Packages/Color Scheme - Default/Cobalt.tmTheme",
"font_face": "BitStream Vera Sans Mono",
"font_size": 10
}
File Settings
You can modify the file settings by updating Preferences > File Settings (Default)
Here are some of my preferred file settings:
"rulers": [80,120,160],
"tab_size": 4,
"translate_tabs_to_spaces": true,
"detect_indentation": true,
"auto_indent": true,
"trim_automatic_white_space": true,
"word_wrap": true,
"wrap_width": 80,
"indent_subsequent_lines": true,
"auto_match_enabled": true,
"draw_minimap_border": true,
"highlight_line": true,
"caret_style": "phase",
"line_padding_top": 0,
"line_padding_bottom": 0,
"scroll_past_end": true,
"draw_white_space": "selection",
"draw_indent_guides": true,
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"save_on_focus_lost": false,
"tab_completion": true,
"shift_tab_unindent": true,
"find_selected_text": true
These are the settings that I like to use, but there are plenty more that you might want to change.
Global Settings
The global settings can be configured via Preferences > Global Settings (Default)
Here is the global setting I file use:
{
"theme": "Default.sublime-theme",
"hot_exit": true,
"remember_open_files": true,
"folder_exclude_patterns": [".svn", ".git", ".hg", "CVS"],
"file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", "*.class", "*.psd", "*.db"],
"binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],
"scroll_speed": 1.0,
"show_tab_close_buttons": true,
"highlight_modified_tabs": false,
"open_files_in_new_window": true,
"close_windows_when_empty": true,
"use_simple_full_screen": false,
"overlay_scroll_bars": "system",
"ignored_packages": []
}
Instead of customizing global settings, it’s safer to override them in user file settings, user global settings, and user key bindings files.
Here is my current User File Settings file:
{
"color_scheme": "Packages/User/Monokai Soda.tmTheme",
"font_face": "Meslo LG S DZ",
"font_size": 10,
"vintage_start_in_command_mode": true
}
And my current User Global Settings file:
{
"theme": "Soda Dark.sublime-theme"
}
And my User Key Bindings File
[
{ "keys": ["ctrl+shift+H"], "command": "highlightCurrentWord" },
{ "keys": ["ctrl+shift+x"], "command": "htmlprettify" }
]
As you see, Sublime Text 2‘s configuration flexibility is almost unlimited. You can edit the configuration files to your liking, and have the most suitable development environment for yourself.
Let’s examine the user interface deeper, shall we?
Everything can be Done from the Keyboard
You don’t need your mouse, or your trackpad when you get used to keyboard shortcuts. This does not mean mouse is useless, though.
Everything can be done from the mouse too. However, if you habituate using keyboard shortcuts, you’ll see that you’ll become more productive.
Some Useful Keyboard Shortcuts
Here are a few (out of many) useful keyboard shortcuts:
- selecting lines of code
- cmd + L
- jump to line number
- cmd + G
- moving code up and down
- cmd + ctrl + (up/down arrows)
- wrapping text selection with a tag
- ctrl + shift + W
- selecting multiple lines
- cmd + shift + L
- selecting multiple lines then wrapping each single one (useful for menus, list items… etc.)
- cmd + shift + L; then cmd + ctrl + W
- selecting multiple columns
- alt + (drag) (enables you select an arbitrary rectangle of text)
Fuzzy Finder (Go to Anything)
All the search in Sublime Text 2 is based on a powerful fuzzy matching algorithm. Which enables you to find DialogControllerComponentFactory class by typing dccf. This is way more quicker than writing a regular expression to grep the right file — it’s almost second nature.
With the keyboard shortcut CTRL+P (fuzzy finder) you can switch between the open files by using the arrow keys.
You just have to type some keys and it will show you a list of files containing these keys. It’s smart though: It’ll order the results by popularity, meaning that the files that you open more will be already at the top of the list.
While switching back and forth with the arrow keys, you can see the contents of the file you switch without even pressing the enter key.
It’s lightning fast. I can say that it’s even faster than VIM applications like PeepOpen.
Command Palette
Another very useful feature of Sublime Text 2 is its Command Palette. You can access it by clicking CTRL+Shift+P. The palette displays a searchable list of all the available commands.
Multi Selection
Yet another indispensable feature of Sublime Text 2 is its multi-selection mode. Once you get used to it, you cannot do without it
.
To select multiple parts of the text, press CTRL (CMD key in Mac) then highlight and click each region where you want to get selected.
Tabbed Layout
With Sublime Text 2, you can easily open multiple documents not only in different tabs, but also side by side.
There are seven alternative screen layouts, allowing you to stack up documents next to, or below, one another.
Themes
If you are not satisfied with the default theme, you can always modify the theme or install another theme. Let us install Ian Hill‘s “Soda” theme, for example.
After extracting the folder contents to Packages/Theme – Soda, you’ll need to update Preferences > Global settings – User with this one
{
"theme": "Soda Dark.sublime-theme"
}
This is enough to start instantly using the new theme.
Color Schemes
There are (by the time of this writing) 22 built-in color schemes for Sublime Text 2. All of them are pleasing to the eye. If you prefer to use your own color scheme though, you can use it by adding your .tmTheme file into the Packages/User folder.
Here’s a color scheme file that uses a modified version of Sublime Text 2‘s default Monokai color scheme.
JSLint Support
If you are a JavaScript developer, JSLint shall be a part of your regular development cycle.
With Eduardo Lundgren‘s JSLint plugin, it’s extremely easy to integrate JSLint to your development cycle.
After adding the plugin’s files to Sublime Text 2‘s configuration folder (which is .config/sublime-text-2/Packages for my environment), and binding the build action to a keyboard shortcut like CTRL+Shift+B, you can JSLint the file you edit with a few keystrokes
.
Trim Trailing Spaces
Another useful sublime plugin is the trailing spaces plug-in.
What it does is simple: It marks the trailing spaces in your source file, and optionally deletes them with an assigned keyboard shortcut. You can even configure the plug-in to trim trailing spaces whenever you save a source file.
Auto Format JavaScript Files
We’ve all worked with those files whose indentation has gone wild, with no consistent usage of braces and spaces, where white-space and tabs are mixed together.
Those files are hard to read, harder to understand and even harder to maintain.
With the Sublime HtmlPrettify plugin, you can auto-format any JavaScript and HTML file.
Installing this plug-in, as any other plug-in can be done by copying the folder contents to Packages/HTMLPrettify folder.
Then adding
{ "keys": ["ctrl+shift+x"], "command": "htmlprettify" },
to Preferences > Key Bindings > User, will map CTRL+SHIFT+x keyboard combination to htmlprettify action, which will auto-format your code.
Zen-Like HTML Creation
Another useful plugin is ZenCoding.
Similar to the plug-ins before, to install, simply copy the ZenCoding folder inside Sublime’s Packages folder.
Zen Coding enables you to convert something like this
div.mydiv>ul#theul>li*5>a[href="http://mylink.com"]+span
into this:
<div class="mydiv">
<ul id="theul">
<li><a href="http://mylink.com"></a><span></span></li>
<li><a href="http://mylink.com"></a><span></span></li>
<li><a href="http://mylink.com"></a><span></span></li>
<li><a href="http://mylink.com"></a><span></span></li>
<li><a href="http://mylink.com"></a><span></span></li>
</ul>
</div>
Highlight Words
Another useful plug-in is the WordHighlight plugin.
Installing the plug-in is similarly easy:
You guessed it! Just copy the folder to Sublime Text 2‘s Packages Folder
.
The plug-in enables you to highlight all occurrences of the word under your cursor.
But… Still VIM is the King of All Editors
I feel the same way you do
. Once you master VIM‘s keyboard commands, you’ll never want to go back to another editor. Before analyzing Sublime Text 2, I’ve felt the same way too. I have always wondered why on earth do IDE creators not integrate a VIM-like text editing behavior to their IDEs.
A decent editor which had all the flexibility and keyboard shortcuts of VIM, along with the power of an IDE would have been great!
What I found is: Sublime Text 2 has a “Vintage Mode”, which easily enables a VIM-like editing environment
.
If you are one of akind who uses l, h, j, k instead of arrow keys, Vintage mode is what you need.
Since VIM is an editor with a slightly steep learning curve, Vintage Mode is not enabled by default. To enable it:
- Select the Preferences/Global Settings – Default menu item,
- Edit the ignored_packages setting, changing it from:
"ignored_packages": ["Vintage"]
to
"ignored_packages": []
Vintage Mode includes most basic actions:
- d (delete),
- y (copy),
- c (change),
- gu (lower case),
- gU (upper case),
- g~ (swap case),
It also includes many motions, including l, h, j, k, W, w, e, E, b, B, alt+w (move by sub-words), alt+W (move backwards by sub-words), $, ^, %, 0, G, gg, f, F, t, T, ^f, ^b, H, M, and L.
That may be not enough for a seasoned VIM fanatic, but it’s more than satisfactory for me
.
I even enabled:
"vintage_start_in_command_mode": true
in my user file settings to start Sublime Text 2 in Command Mode every time I open a file.
MiniMap
You can see your code from 10,000 feet with Sublime Text 2‘s MiniMap.
MiniMap is a little map on the right of the editor, showing an overall view of the entire code.
I found that the MiniMap works best when you’re trying to discipline yourself to keep your files small:
Large classes in with tons of methods, with deeply nested code blocks become really obvious when the MiniMap is right there staring at you all the time.
Code Snippets
Yet another powerful feature of Sublime Text 2 is code snippets.
Let’s see one by example:
Click Tools > New Snippet
and paste the following snippet there:
<snippet>
<content><![CDATA[
/**
* ${1:function} \{${2:identifier}\} ${3:methodName}
*
* <p>${4:description}.</p>
*
* @param \{${5:type}\} ${6:name} - ${7:description}
* @return ${8:what}
*/
]]></content>
<tabTrigger>/**</tabTrigger>
</snippet>
then save it as jscomment.sublime-snippet.
After that, any time you type /** and press the TAB key, the editor will automatically paste this:
/**
* function {identifier} methodName
*
* <p>description.</p>
*
* @param {type} name - description
* @return what
*/
Where you can navigate between tab stops by clicking the TAB key further.
Distraction-Free (i.e. Blogging) Mode
It’s the mode that I use when I was drafting this article
.
It’s simple one but really useful. In Distraction-Free Mode, the editor goes into full screen and your text is centered in the middle of the screen. There’s nothing to distract you: no menu bar, no MiniMap. The only thing you focus is your text.
Simple, and awesome!
Unofficial Documentation
There is a comprehensive documentation of Sublime text on docs.sublimetext.info. The docs are well-organized and helpful.
Package Control
Install Sublime Package Control in order to magically pull and install plugins from github.
If you are like me, and want to experiment with different addons/plugins, then the first thing you install must be Package Control in deed.
Useful Sublime Text 2 Plugins
Here are a few other useful Sublime Text 2 plugins:
- Sublime Alignment
- A key binding to align multiple lines and multiple selections, for code readability.
- Sublime Change Quotes
- Enables changing the selection from single quotes to double quotes, trying to intelligently escape quotes whenever possible.
- Case Conversion
- Case conversion converts the current word/token between pascal, camel, and snake case.
- Bracket Highlighter
- A must-have extension, if you are a frequent code writer (i.e. a programmer
) - Sublime Tag
- Currently provides: “Close tag on slash”, “Tag indent or AutoFormat Tags”, “Tag Remove”, “Insert as Tag”, “Tag Remove Attributes”, “Tag Close”, “Tag Lint”. If you edit a lot of HTML/XML documents then this plugin is a life-saver
- Clipboard History
- Keep a history of your clipboard items. Let you paste them back in, as needed.
Conclusion
Sublime Text 2 is an editor I fell in love with. I’m sure I’ve only scratched the surface of it, and I’m pretty sure I will keep finding new things for Sublime Text 2 as I continue using it more.
Sublime Text is trial-ware: However, it doesn’t seem to have a time or feature restriction on the trial. In other words, you can use the trial as long as you like, without any inconvenience.
That aside, I must admit that the developers of Sublime Text 2 did one hell of a job. I will spare the money, and thereby support the people that made this possible. I urge you to do so too.
…
Have you tried Sublime Text 2? If so, what was your experience?
What are the Sublime Text 2 plugins that you cannot live without?
What coding environment do you currently use?
Don’t be shy; share your experiences in the comments below
.










Very nice article Volkan. I’ve touched on sublime on my blog as well (see below). Also, excellent articles on JavaScript in general! Your o2 framework is quite interesting. I’m surprised you’re not getting more comments… it’ll just be a matter of time. Good luck!
http://blog.elemdage.com/technology/one-mans-html5-developer-workflow
Hi Gene,
Thank you very much for your motivating comment.
As far as the stats are concerned people are staying and enjoying the content.
.
There are many lurkers, and little posters, so to speak
Though that does not disappoint me much:
As long as I add value to the community, I am happy to share my knowledge and experience.
You have an excellent blog as well.
Keep adding more value
p.s.
I am currently focused on (re)organizing o2.js framework code, fixing bugs, and adding new modules and functionality.
I will be adding new articles soon. So stay tuned
.
Cheers.
Also surprised at the lack of comments. Great article here! Exactly what I needed to help me make ST2 my own.
Justin, I’m glad to help
.
It took a lot of time to put together all these plugins and make Sublime ideal for my development needs.
And I wanted to share my experience so that others can avoid all the hassle
Just a correction:
Multi-selection is done using the Ctrl key. The Alt key is used to unselect a word.
Other than that, great article. Thanks for the Trim Trailing Spaces tip.
Hi Patrick,
Thanks for the update. Fixing the article accordingly.
Cheers.
FYI, I added a link to this article as well as a few other o2.js links to my Master List of HTML5, JS, CSS Resources, here:
https://github.com/gloparco/Master-List-of-HTML5-JS-CSS-Resources
Thanks for the heads up, Gene.
It takes a lot time and effort to curate such a list.
I am bookmarking it, watching the repository, and I will be sharing it with my friends and colleagues.
Well, I shall add a comment. I probably a different perspective than the other peops. My children do not need me anymore
. Thus, it’s time to update the “OLD” computer skills. <>
I tried Sublime 2 several months ago and I am not sure if I was just too rusty at that time or perhaps you are just awesome! This article is wonderful.
I am a novice, and your information opened up Sublime2 for me, and I hope anyone reading this will not be intimidated with the customization “setting it up” process. Most of the tips and hints I found surfing intimidated me until I read this article.
Thank you very much!
Hi Stephanie,
Thanks for your compliments.
I’m glad you find this article useful, and I am happy that it helped you to find your way around.
Every editor has it’s own pros and cons. Sublime for instance, is much more user-friendly than VIM, and much lighter than NetBeans, with a tiny learning curve, which you’ve seen that it’s a cakewalk once you are in the right mood.
VIM, on the other hand, is a god-damn powerful editor, with the steepest learning curve you can imagine. I also recommend you to give it a shot, if you haven’t already.
I’ve been using Sublime for a while, and I’ve learned several tips & tricks along the way. I’ve not mentioned them in this tutorial yey.
And I plan to update this article soon with those new cards in my sleeve
Cheers!
very useful blog, thanks for all the things you’ve pointed out, now I’m using Sublime 2.
One thing I want to ask, can you tell me what plugin/ config you used to show the trailing space in color ? glad you can help
Hi Duc,
That color is defined in the theme file.
In my linux machine it is located at
/home/volkan/.config/sublime-text-2/Packages/Color Scheme (Default)/{themeName}.tmTheme
You can modify it by editing the file and changing the hex code of selection dictionary key.
It should be something similar to this:
[key]selection[/key]
[string]#80000080[/string]
Hope that helps.
[...] An Editor You Will Regret You Haven’t Used Before [...]
Hey I just wanted to thank you for this awesome guide. I was looking for an alternative to Aptana Studio and came across this. Sublime Text 2 changed my life!
Excellent intro to Sublime Text 2! I don’t get how people can withstand all that “Indexing” stuff. It was the reason I discarded Zend Studio completely a few years ago despite it’s excellent integration with PHP. Currently I’m using phpDesigner mostly for its speed and unlimited auto-complete and cross-file capabilities (e.g. Ctrl+click, in PHP/JS/CSS/…). But I’ve tried Sublime and PhpStorm and may be using them in near future. Sublime’s speed is unbelievable even on Windows. Vim could be another option but I feel a little bit old to start with it
Hi Halil,
Yes, sublime is a great editor. And it’s event better on Mac in fullscreen mode. (actually once you get used to Mac, you’ll never go back — but that’s another story
)
VIM is also a great editor, especially when you do not have a GUI and a mouse/trackpad around. And when your operating system allows graphical user interface integration, sticking to vim is kind of overkill.
One place VIM shines (and sublime falls short) is remotely editing files. Remote file editing using Sublime is not that smooth and you may have to use plugins like Sublime SFTP or expandrive.
Bottom line is, I’d love to use VIM if I have to. However I’ll prefer sublime text when I have a choice
Cheers.
[...] the cool kids nowadays, I’ve switched to Sublime Text 2 for code wrangling. Sublime rocks for ton of reasons but I was always depressed when I had to switch back to Eclipse for Force.com work. Luckily about [...]
I’ve used Sublime Text 2 for about 3 days in a row, I liked it a lot, but was not good enough to replace Eclipse IDE as my primary dev tool. Since Eclipse has a lot of plugins like MyLyn integration that allows me to connect to bugzilla and rally to keep an Eye on my tasks an even attach a context to a task. Also, Eclipse displays to me the DocBlock documentation of a function by just hovering the mouse and on the autocomplete suggestion box.
Another useful things I miss from Eclipse that Sublime Text 2 does not have yet are: Outline of a file, to view all the functions and properties of it. A visual indicator to know if a file has changes not yet committed. And of course, profiling and debugging.
But I definitely still use Sublime Text 2, since it’s fast and has a very handy sftp integration that allows me to upload a file with just a few keystrokes (I was using CyberDuck for FTP File upload), so now instead of having CyberDuck and Eclipse opened, I just have Eclipse and SublimeText opened while developing.
I want to share this SublimeText 2 course:
http://www.youtube.com/watch?v=TZ-bgcJ6fQo
Thanks for the link Marco,
I’ve also started using Sublime Text3.
I can say that Sublime is a great IDE for doing JavaScript/HTML5 front-end development.
I totally see that a minimalistic approach is not for everyone.
As long as your IDE does not slow you down, and you’re %100 productive with it, it’s best to code in an environment you feel familiar with.
Though exploring different options, and being open to trying alternatives, should also be in any developer’s mindset — not only in editors, but in everything.
For instance, being a Java fan, you should not bash ruby on rails, if you’ve not coded ruby for several years.
It’s the flexibility, and the gratification we have in trying new things, what makes us excel at what we do (i.e. providing creating solutions to hard-to-solve problems)
What we do requires creativity, and the fuel of creativity is constantly trying new things with an open mind.
I know people who enjoy the added utilities of heavier IDEs (like eclipse or intelliJ) with the cost of additional 2gigs of RAM utilization.
intelliJ for example has excellent source control integration; you can browse annotations, and commit comments that others make while you code. You can do diffs/checkins/checkout without needing to leave your IDE. you can integrate it with ANT. — Since RAM is cheap nowadays, it’s best to code in the platform you feel most comfortable with.
Though I’m still amazed how fast and convenient Sublime Text 2 (and 3) is.
I’m so amazed, that I’ve paid for a license for it. And it’s still a major part of my daily coding workflow.
Thanks again for the tutorial.
Cheers.