Piotr Banaszkiewicz

Sublime Text 3 for Python development

On Saturday 24 Aug, 2013

I’ve been heavy vim user for a couple of years. I had a very cool con­fig­u­ra­tion, really got all these fancy vim key shortcuts muscle-memorized.

But then vim plugins (bundles) started annoying me. Often my con­fig­u­ra­tion become obsolete after an upgrade. I had to go through doc­u­men­ta­tion and set everything once again.

So I decided to give Sublime Text 2 a try. And in August 2013 I switched almost completely. I still love vim, but now I program mainly in Sublime Text 3.

Why switch to Sublime Text 3?

For me, these are the reasons:

  • Sublime Text 3 is sooo pretty
  • it’s also so freaking fast, way faster than Sublime Text 2
  • vast range of plugins, easy con­fig­u­ra­tion

Not much, you say? It was enough to made me switch editors.

Brief history

Sublime Text 2 was using Python 2.x as an API in­ter­preter. Early in 2013, first build of Sublime Text 3 appeared, not even remotely complete. And it shipped with Python 3.3 in­ter­preter.

Since then, Sublime Text 3 (now beta build 3047 or bleeding edge dev build 3052) has come a long way and can be used by everyday programmer.

What’s important is that many Sublime Text 2 plugins have been either ported or made Python2/3 compatible.

Con­fig­u­ra­tion

Theme

There’s lots and lots of themes for Sublime Text 3. I currently use Monokai Extended, with Soda dark theme.

Perv Orange is also very good, but a bit darker than Monokai.

Both schemes have better re­struc­tured­Text coloring. Default Sublime Text 3 syntax high­light­ing for rsT is… in a poor state.

Soda theme with Monokai Extended color scheme

Visual preview of my current con­fig­u­ra­tion.

Some visual settings:

{
    "always_show_minimap_viewport": true,
    "bold_folder_labels": true,
    "draw_minimap_border": true,
    "highlight_modified_tabs": true,
    "indent_guide_options":
    [
        "draw_active",
        "draw_normal"
    ],
    "soda_classic_tabs": true,
    "soda_folder_icons": false,
}

Typeface

I’ve tested Consolas, Monaco, Ubuntu Mono and Meslo. Last two are my favorite, I switch them back and forth very often.

Con­fig­u­ra­tion for Meslo:

{
    "font_face": "Meslo LG L",
    "font_size": 10,
    "line_padding_bottom": 0,
    "line_padding_top": 0,
}

Con­fig­u­ra­tion for Ubuntu Mono:

{
    "font_face": "Ubuntu Mono",
    "font_size": 12,
    "line_padding_bottom": 1,
    "line_padding_top": 1,
}

And some additional typeface-agnostinc but font-related settings:

{
    "caret_style": "solid",
    "font_options":
    [
        "subpixel_antialias"
    ],
    "highlight_line": true,
}

Python

This part of con­fig­u­ra­tion helps with writing Python.

{
    "ensure_newline_at_eof_on_save": true,
    "folder_exclude_patterns":
    [
        ".svn",
        ".git",
        ".hg",
        "CVS",
        "__pycache__"
    ],
    "indent_to_bracket": true,
    "rulers":
    [
        79
    ],
    "shift_tab_unindent": true,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "wrap_width": 80
}

Behavior

Fixes some minor annoyings, like opening a preview after selecting file in side bar.

{
    "enable_telemetry": false,
    "preview_on_click": false,
    "shift_tab_unindent": true,
    "show_panel_on_build": false,
}

Note

You can change some settings on a per-project basis. Simply open your project.sublime-project file (Project → Edit Project) and add settings section:

{
    "folders":
    [
        ...
    ],
    "settings":
    {
        "python_interpreter": "/home/piotr/.virtualenvs/project/bin/python"
    }
}

Con­fig­u­ra­tion file

For lazy people: https://gist.github.com/6351258.

Plugins

These are the plugins I can’t live (and program) without. Absolutely necessary.

Package Control

A package manager for Sublime Text 3. Helps you search for, install, upgrade and remove most of available Sublime Text 3 packages.

Git

Very popular and quite easy for basic ap­pli­ca­tion. There’s also some payable SublimeGit plugin I haven’t tried out yet. (It seems nice, though!)

Update 30.08.2013: I switched to SublimeGit plugin. It’s very similar to vim’s fugitive, so I’m already feeling good about it. Definitely well spent money on an al­ter­na­tive to Git.

GitGutter

Adds small icons in left margin indicating which lines have been added, modified or deleted.

GitGutter icons example

GitGutter icons: for deleted, added and modified lines.

Side­BarEn­hance­ments

Adds obvious (but missing from pure Sublime Text 3!) context menu options for side bar.

GitGutter icons example

Additional items in side bar’s context menu.

Anaconda

So far, the best Python completion and linter for Sublime Text 3. You can believe me, I tested other ones, too.

Anaconda is actively developed, and it’s author is very responsive.

I highly recommend installing this package from git, as I’m not sure if recent critical patches were already pulled in by Package Control.

Gist

This plugins helps managing (adding, editing and removing) GitHub gists. Needs a little bit of con­fig­u­ra­tion efforts, but it’s generally worthwhile.

Warning

After installing each plugin, check if your con­fig­u­ra­tion and favorite key bindings still work. It will be harmful for you to discover after pulling in four plugins that one of them disabled selecting multiple cosecutive lines separately (Shift+Alt+Up/Down) or inserting multiple carets in EOLs in your selection (Ctrl+Shift+L).

I even recall some plugin changing behavior of inserting brackets around selection! That was just mean…

Final words

I hope I was somehow able to help you boost your Python de­vel­op­ment or encourage to use Sublime Text 3. Have a good time and nothing to debug!

Blog comments powered by Disqus