Skip to content

Getting Started with Sublime Text

David Ensinger

Although I switched to Sublime Text more than a year ago, I only recently decided to take a good look at my configuration, with the end goal of increasing my productivity. What follows are my settings, which will hopefully help others work a bit smarter. If you’ve got any useful tips, please tweet at me!

Hide Files and Folders

It’s often helpful to hide folders so they’re not found when searching or using the Go to File shortcut (⌘ + T). Add the following line to your User Preferences (Preferences › Settings - User or ⌘,) to do so:

"folder_exclude_patterns": [".git", ".svn", ".sass-cache"]

You can also use exclude file types (with asterisk), instead of directories:

"file_exclude_patterns": [".DS_Store", "*.log", "*.psd"]

Open Files as Tabs

The default behavior is to open a file in a new window. If you’d prefer tabs, add this line to your User Preferences (Preferences › Settings - User or ⌘,):

"open_files_in_new_window": false

Close Windows when Empty

To close the window when there are only empty tabs, add this line to your User Preferences (Preferences › Settings - User or ⌘,):

"close_windows_when_empty": true,

Pasting

Some projects use tabs, while others use spaces. It’s nice to easily copy and paste snippets of code between the two, without worrying about the indentation.

To adjust your indentation to match the context in which it’s pasted, use “Paste and Indent” for ⌘V instead of the standard “Paste.”

To do this, add the following in your Key Bindings - User file:

{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" }

Shortcuts

There are a lot of really useful keyboard shortcuts in Sublime Text. Instead of listing them all, I’m going to list some favorites. With a quick search of the internet you’ll surely find more to integrate into your workflow.

  • ⌘L - Select line
  • ⌘D - Select word (use this to select other occurrences, which is great for multiple editing)
  • ⌘P - Goto anything (use # to search within file and : to go to a line number)
  • ⌘⌃G - Select all occurrences of current word (again, helpful for multiple editing)
  • ⌃⌘↑ (up) or ↓(down) - Swap lines either up or down

More Info: Here’s a Gist of Useful Shortcuts.

Package Control

One of the best things about Sublime Text is how extensible it is. There are hundreds of community developed plugins and with Package Control it’s quick and easy to install, update, and remove them from your installation.

Installation

  1. Open Sublime Text and press ctrl ` (control backtick) to open the editor’s console.
  2. Paste in the following code:
import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

Favorite Packages

There are also innumerable packages to support syntax highlighting, linting, and snippets in any and all languages. You can easily discover these via Package Control.

Spaces

Open TrailingSpace’s preferences (Preferences › Package Settings › TrailingSpaces › Settings - User), and add:

"trailing_spaces_include_current_line": false

Also add this to your global user preferences (⌘,):

"trim_trailing_white_space_on_save": true

Tabs to Spaces

The default indentation style uses tabs instead of spaces. If you want to change this, go to your User Preferences (Preferences › Settings - User or ⌘,) and add:

"tab_size": 2,
"translate_tabs_to_spaces": true

Scroll

To scroll past the end of the file, add this to your User Preferences (Preferences › Settings - User or ⌘,):

"scroll_past_end": true,
"scroll_speed": 2

Other Resources

There are a multitude of resources available to users of Sublime Text. Here are some good ones to read through: