Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 29, 2011 11:03 pm GMT

Sublime Text 2 Tips and Tricks

I consider Sublime Text 2 to be the spiritual successor to TextMate – particularly when the likelihood of TextMate 2 coming to fruition becomes bleaker and bleaker. When Duke Nukem Forever is released before TextMate 2, you know you’re in trouble! But that’s okay, because Sublime Text 2 is one of the fastest and most incredible editors to come out in a long time! I’ll show you my favorite tips and tricks today.

Sublime Text 2 is currently available for all major platforms: OS X, Linux and Windows.


1 – Get a Better Icon

In its defense, Sublime Text 2 is still in a beta state. The official icon will likely/hopefully change with the official release. Until then, Nate Beaty created an excellent substitute.

To integrate it, you need to replace the existing “Sublime Text 2.icns” file with this new one. On a Mac, browse to Sublime 2 in your Applications/ folder, then right-click and “View Package Contents.” Lastly, browse to Contents/Resources/, and drag the new icon in, overwriting the existing one.


2 – Bleeding Edge Versions

Sublime is in active development. If, like me, you want to use the latest possible version of the app, you can download the dev build. You’ll find that new (auto) updates are available every other day or so.

Download a dev build of Sublime 2 here.


3 – Access the Command Palette

Similar to TextMate, we can use Sublime’s command palette by accessing the Tools menu, or by pressing Shift + Command + P, on the Mac. Whether you need to visit a Preferences page, or paste in a snippet, all of that can be accomplished here.

Access the command palette

4 – Lightning-Fast File Switching

File Switching

Press Control or Command + P, type in the name of the file you wish to access (fuzzy finder), and, without even pressing Enter, you’ll instantly be transported to that file. While Vim and apps like PeepOpen offer a similar functionality, they’re not nearly as fast as Sublime’s implementation.


5 – How Did We Survive Before Multi-Selection?

Editors like TextMate have long offered vertical selection, which is quite neat. But, with multi-selection, you can have multiple cursors on the page. This can drastically reduce the need for using regular expressions, and advanced search and replace queries. Perhaps a quick visual demonstration is in order…

To enable multi-selection, you have two options:

  • Press Alt or Command and then click in each region where you require a cursor.
  • Select a block of lines, and then press Shift + Command + L.

6 – Indent Guides

It’s such a small feature, but I’ve always loved how Notepad++ on Windows displays indent guides; it makes the page much easier to navigate and format. Sublime Text 2 offers this ability, via a plugin created by Nikolaus Wittenstein.

Indent Guides

To integrate this plugin:

  • Download it
  • Rename the folder to “Indent Guides” and drag it into the Packages folder. On a Mac, this path would be Application Support/Sublime Text 2/Packages

7 – Package Control

The steps outlined in the previous tip (#6) are a bit tedious, aren’t they? Instead, we can install the excellent Sublime Package Control, which streamlines the entire process.

To install “Package Control,” open Sublime and press Control + `. Next, paste the following snippet into the console.

 import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('https://sublime.wbond.net/'+pf.replace(' ','%20')).read())

Don’t worry if you don’t understand the code above; just copy and paste!

Console

Lastly, restart Sublime Text, and browse to Preferences -> Package Settings. If the installation was successful, you’ll now see a Package Control item in that list.

With Package Control installed, the process of adding new plugins and functionality becomes incredibly simple!

For a usage example, refer to the next item in this list.


8 – Alignment

If you’re the type who prefers to line up your equal signs – for example, in your JavaScript…

// Beforevar joe = 'joe';var johnny = 'johnny';var quaid = 'quaid';// Aftervar joe    = 'joe';var johnny = 'johnny';var quaid  = 'quaid';

…this process can be automated, via the Sublime Alignment plugin. Rather than downloading and installing it manually, let’s instead use Package Control (outlined in #7).

  • Press Shift + Command + P
  • Type “install,” to bring up the “Package Control: Install Package” option, and press Enter
  • Look for “Alignment,” and press Enter to install it.
  • You’re done; so easy! Type Shift + Command + A to auto-align.
Auto-align

This process can be repeated for all of the typical plugins we install, such as Zen Coding.


9 – Vim Fanatic

I’m a huge fan of Vim. The amount of power it provides is insane. The fact that I’ve switched over to Sublime Text 2 should speak volumes then!

If you’re using a dev build of Sublime Text (see #2 in this list), you can enable Vintage mode, which provides support for the Vi commands that we know and love — okay…some of us love. The rest of you hate it! :)

To enable Vintage mode, browse to Preferences/Global Settings - Default. Once this file opens, browse to the very bottom, and change "ignored_packages": ["Vintage"] to "ignored_packages": []. Next, restart Sublime, press the Escape key, and, tada: command mode!


10 – Distraction Free Editing

Sometimes, we need to filter out all of the additional fluff that gets in the way of our coding. Use “Distraction Free Mode” to take this idea as far as possible. This option is available, via the View menu. Select “Enter Distraction Free Mode,” or use the Mac keyboard shortcut, Control + Shift + Command + F.

Distraction Free Mode

11 – You Can Still Use TextMate Bundles

Slim

TextMate snippets and themes port over nicely to Sublime Text. You only need to drop them in the Packages folder — .tmbundle extension intact, and Sublime will recognize the files. This means that the entire catalog of TextMate themes will work in Sublime!

For example, I’ve been working with the (fantastic) Slim templating engine a good bit lately, and needed better syntax highlighting. Fred Wu created a bundle for TextMate, but, tada, it works perfectly in Sublime Text as well! If you’re interested, you can download the Slim bundle here; it includes both snippets and syntax highlighting.


12 – Custom Themes

The default theme for Sublime Text is excellent, but I much prefer a custom light and dark theme, Soda, created by Ian Hill.

Soda Theme

Installation

As taken from the Github page…

“If you are a git user, the best way to install the theme and keep up to date is to clone the repo directly into your Packages directory in the Sublime Text 2 application settings area.”

Using Git

Go to your Sublime Text 2 Packages directory and clone the theme repository using the command below:

 git clone https://github.com/buymeasoda/soda-theme/ "Theme - Soda"

Download Manually

  • Download the files using the GitHub .zip download option.
  • Unzip the files and rename the folder to Theme – Soda
  • Copy the folder to your Sublime Text 2 Packages directory

Activating the Theme

To configure Sublime Text 2 to use the theme:

  • Open your Sublime Text 2 User Global Preferences file: Sublime Text 2 -> Preferences -> User Global Settings
  • Add (or update) your theme entry to be “theme”: “Soda Light.sublime-theme” or “theme”: “Soda Dark.sublime-theme”

Example User Global Settings

{    "theme": "Soda Light.sublime-theme"}

Conclusion

The more I work with Sublime Text 2, the more I realize how incredible it is. But all of this would mean nothing if not for the fact that it’s an insanely fast editor, and, even better, it’s not finished!



Original Link: http://feedproxy.google.com/~r/nettuts/~3/WNm6XMj3o-8/

Share this article:    Share on Facebook
View Full Article

TutsPlus - Code

Tuts+ is a site aimed at web developers and designers offering tutorials and articles on technologies, skills and techniques to improve how you design and build websites.

More About this Source Visit TutsPlus - Code