by Martin Breuss, CodingNomads

This article was originally published on Medium.com.

Sublime Text’s rich package ecosystem makes it possible to fine-tune the text editor specifically to what you are using it for. Some of the packages are universally helpful, others, such as syntax checking, are specific to the programming language you are working with.

The Python course I’ll be co-teaching this summer is focused on web development with Python 3, so here’s a guide to optimally tune Sublime for that.

Changing settings is easy and might also help to clarify how to do further customizations — if that is where your ❤ is at.

 

Sublime Settings

Before moving onto installing plugins, there are a couple of useful settings that can help to tailor Sublime for python development. Go to Sublime Text → Preferences → Settings and in the Preferences.sublime.settings-User file enter the following rules:

{
    "spell_check": false,
    "rulers":
    [
        72, 79
    ],
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "ensure_newline_at_eof_on_save": true
}

I personally prefer to keep “spell_check” on false because I don’t like to see red lines everywhere when writing non-dictionary-compliant words. Maybe I’m just damaged by the school system. If you have a different opinion on this, simply set “spell_check” to true.

The magic numbers for the “rulers” setting originate from pythons PEP8. Docstrings and comments should be limited to 72 characters and all other lines should not be longer than 79 characters. The ruler lines can help to remind you when you are approaching these limits.

In good python fashion we set the “tab_size” to 4 and “translat_tabs_to_spaces” to avoid relationship troubles.

 

Finally, we can get another PEP8 compliance automation with “ensure_newline_at_eof_on_save” which does just that: adding a single newline at the end of the file when you save the document.

 

Packages (Plugins)

And now we dive right into the pool of great packages for Sublime Text that extend its functionality and can make your life as a programmer easier and more colorful!

 

SidebarEnhancement

Power-up for the ST sidebar, introducing useful features such as being able to create new files directly from there and sending files to the recycle bin when they are deleted from inside Sublime.

 

Anaconda

Note: this is not the popular python distribution often used for data science that goes by the same name.

The Sublime Text Anaconda plugin helps to make ST more IDE-like while keeping it still operating much quicker than most IDEs. It introduces easy access to useful features such as:

  • Code autocompletion
  • Code linting: syntax errors
  • Code linting: highlight and automatically fix PEP8 violations
  • Python documentation on class, method or function under the cursor
  • Goto Python definition anywhere in the project
  • Find object usage across the project
  • and lots more…

 

Auto Docstring

Auto Docstring does just what its name suggests — it allows you to swiftly create a Python docstring template for your selected function, method or class. You can even add docstrings for every function in a file and change between Google and Numpy style even after the docstrings were created. A very basic auto-generated example would look like this:

def my_function():
    """Summary
    
    Returns:
        TYPE: Description
    """
	return None

SublimeLinter

For python syntax and PEP8 you could stick with using the linting provided through the Anaconda plugin. However, using SublimeLinter has the advantage that it is extensible also with other linters that are useful for web development. That’s why I would suggest to disable Anaconda’s linter, like so:

Use the file menu: Sublime → Preferences → Package Settings → Anaconda → Settings — User to go to the user-defined Anaconda settings file. Then set: {"anaconda_linting": false}

Now, install SublimeLinter using the Package Manager.

 

Note: Most of the linters require additional packages to operate correctly, so make sure to read the instructions carefully

 

SublimeLinter-pyflakes
pyflakes
 performs syntax checking on python files. This package needs to be installed using pip before adding it to ST with the Package Manager

 

SublimeLinter-pycodestyle
pycodestyle
 is the new name of the pep8 package. Install it using pip, then add it to Sublime using the Package Manager for PEP8-compliant code style linting.

 

Other useful linters for web development:

 

Djaneiro

This useful plugin adds a couple of handy Django snippets with tab autocompletion into ST to make working on web projects quicker.

 

E.g. block + TAB generates {% block %}{% endblock %}

 

 

Very cool. Check out all it has to offer here!

 

Git

Allows to do the most common set of git commands from within Sublime.
git add, commit, push etc. right from your favorite text editor.

 

GitGutter

GitGutter helps to keep track of which files have been edited since the last commit. It adds small symbols next to the line numbers that indicate their status in relation to the git repository.

 

 

requirementstxt

Introduces syntax highlighting for requirements.txt files. Be good to your 👀!

 

Markdown Preview

Allows to preview Markdown documents in your browser — build them using different available flavors!

 

Other useful Web Dev Packages

CSS3
The CSS3 plugin allows for futuristic CSS syntax highlighting. You’ll need to tweak the rest of the settings a bit, but it’s easy to follow along the steps here:

 

ColorHighlighter
This one is fun. Adds more 🌈 to your code. Hex color values will be displayed with the corresponding color as background. Makes it easier to remember what color you were adding where.

 

Emmet
If you’re excited about automating the repetitive parts of your web development work, then Emmet can be a big help. Install the package, then learn how to benefit: https://docs.emmet.io/cheat-sheet/

 

Want to learn more? Come to our Python training course in Barcelona!

With adding these packages and tweaking the settings as mentioned above, Sublime Text becomes a lightweight but powerful editor for web development with python.

If you are just getting started and are looking for a fun and affordable bootcamp that helps you to learn programming and gets you to travel and see the world, check out CodingNomads and the bootcamp I’ll be co-teaching this September in Barcelona. 🌇 💻 🎒🏝

 

More Info:

Plugin Setup:

Learn to increase your performance when working with ST3:

 

READ NEXT: How to find a job after a coding bootcamp