Skip to content

Instantly share code, notes, and snippets.

@discort
Forked from ijy/sublime-text-3-setup.md
Last active May 7, 2021 22:27
Show Gist options
  • Save discort/510e0578b396e16643b6171d422365b5 to your computer and use it in GitHub Desktop.
Save discort/510e0578b396e16643b6171d422365b5 to your computer and use it in GitHub Desktop.
My Sublime Text 3 setup.

Sublime Text 3 Setup

Install Package Control

Install Package Control for easy package management.

  1. Open the console with Ctrl+`
  2. Paste in the following:
import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

From here on out, use Package Control to install everything. +Shift+P, then type Install to get a list of installable packages you can livesearch through. Watch the Status Bar for installation progress.

Add Some Style

Install Material Theme for some UI customisations. You'll need to restart Sublime after installation for the changes to take effect.

Add Some Useful Packages

All installed with Package Manager. +Shift+P and type install. Then start typing the name of the extension you want to install.

Sublime Text Extensions

  • Anaconda - fantastic Python "IDE" support for Sublime Text. Just works, does everything you'd want it to do, including code completion and PEP8 checking
  • SideBarEnhancements - enhances the sidebar context menu options. Easily create new files and folders, etc.
  • Package Control - (obviously)
  • Python 3 - Python 3 and Cython language bundles for Sublime Text.

Syntax Packages

Settings - User

Accessible via: SublimeTextPreferencesSettings – User, or with +`,'.'

This is a JSON file of custom user configuration settings. Kept in alphabetical order for easy reference.

Note: As a JSON file no comments can be included. Any you add will be stripped out on saving.

{
	"always_show_minimap_viewport": true,
	"auto_find_in_selection": true,
	"bold_folder_labels": true,
	"close_windows_when_empty": true,
	"color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme",
	"create_window_at_startup": false,
	"drag_text": false,
	"font_face": "Monaco",
	"font_options":
	[
		"gray_antialias",
		"subpixel_antialias"
	],
	"font_size": 13,
	"ignored_packages":
	[
		"Vintage"
	],
	"indent_guide_options":
	[
		"draw_normal",
		"draw_active"
	],
	"line_padding_bottom": 3,
	"line_padding_top": 3,
	"match_brackets_angle": true,
	"overlay_scroll_bars": "enabled",
	"theme": "Material-Theme.sublime-theme",
	"translate_tabs_to_spaces": true,
	"trim_trailing_white_space_on_save": true
}

A complete list of Settings can be referenced in SublimeTextPreferencesSettings – Default.

Override any which aren't to your taste.

Key Bindings - User

Accessible via: SublimeTextPreferencesKey Bindings – User.

Key bindings are the productivity engine which allow you to become one with your text editor. I try to stick with all the defaults to make for an easy install and less chance of potential future clashes. The following are a few small edits I make along with some package specific controls:

[
    // Reveal the currently open file in the sidebar
    { "keys": ["ctrl+super+r"], "command": "reveal_in_side_bar" },

    // AdvancedNewFile
    { "keys": ["ctrl+alt+n"], "command": "advanced_new_file_new" },

    // Create a new snippet [Jeffrey Way]
    { "keys": ["alt+super+n"], "command": "new_snippet" },

    // Open iTerm
    { "keys": ["ctrl+alt+t"], "command": "open_terminal" },

    // Select (or type) the syntax to apply to the current view.
    { "keys": ["ctrl+shift+y"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Set Syntax: "} },

    { "keys": ["super+i"], "command": "copy_path" },

    // Wrap selection in tag
    {
        "keys"      :   ["alt+shift+t"],
        "command"   :   "insert_snippet",
        "args": {
            "contents": "<${1:p}>${0:$SELECTION}</${1}>"
        }
    },

]

More info on Key Bindings can be found in the unofficial docs.

Sublime from the Command Line

Sublime Text includes a command line tool which you just need to symlink up so that it's in your PATH file. In Sublime Text 3 simply copy this into a terminal session:

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Then you can open files in Sublime Text from the command line with:

subl my_file.txt

Replacing my_file.text with the name of the file or folder you wish to open in Sublime Text.

Sublime Text Dropbox Sync

If you switch between Macs at home and work then syncing via Dropbox is a huge time saver. To do this you only need to symlink your Packages and Installed Packages directories to a location in your Dropbox. Then symlink on the device your setting up to sync with those folders on Dropbox.

Always make sure you backup your Packages and Installed Packages folders first - just in case anything goes wrong.

So, once I have Sublime Text 3 installed on my MacBook Pro, I just need to create a symlink for both my Packages and Installed Packages directories in my Dropbox folder:

ln -s ~/Library/Application\ Support/Sublime\ Text\ 3/Packages ~/Dropbox/Sync/Sublime\ Text\ 3/Packages

ln -s ~/Library/Application\ Support/Sublime\ Text\ 3/Installed\ Packages ~/Dropbox/Sync/Sublime\ Text\ 3/Installed\ Packages

Then on my MacBook Air I just need to install Sublime Text 3 (basic install with none of the above) and tell it to look in Dropbox for the Package information:

ln -s ~/Dropbox/Sync/Sublime\ Text\ 3/Packages ~/Library/Application\ Support/Sublime\ Text\ 3/Packages

ln -s ~/Dropbox/Sync/Sublime\ Text\ 3/Installed\ Packages ~/Library/Application\ Support/Sublime\ Text\ 3/Installed\ Packages

Now whenever you tweak any settings or install any new packages the changes will be applied to all shared computers.

Useful Shortcuts

Follow my other gist for useful Sublime Text shortcuts (on a Mac). Commit these to muscle memory and you'll amaze and scare your friends and colleagues with your crazy text editor wizardry.

Learn the Basics

Make sure you get familiar with the extremely useful Find in Files feature along with Fuzzy searches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment