Programmers like to quibble about who has the 'best' development environment - what are the best tools? Should I use a text editor or a full-blown IDE? Which plugins and packages should I be using? These are all valid questions, but the bottom line is this: once you have chosen your preferred text editor/IDE you should spend a considerable amount of time configuring it and learning how to get the most out of it - this will save you time in the long run.

My choice of text editor is Sublime Text 3. In this article I will give you a five-step tutorial on how to set up Sublime Text 3 for development with Python.

1. Installation

You can download and install Sublime Text 3 here.

After installation, the first thing you want to do is install the package manager. The package manager allows you to add and remove third-party plugins which will improve your development environment.

Open the Sublime console with CTRL + `. Then copy and paste the code from here into the console and hit enter. The package installer will take a few seconds to install. Afterwards, you can open up the command pallette with CTRL + SHIFT + P, and type package. A list of options should appear as follows:

package installer sublime text 3

If you see the package control options then you know you have installed it successfully!

2. Recommended Sublime Text 3 Plugins

One of the best things about Sublime Text is that developers can use 3rd party plugins to enhance their development environment. Hit `CTRL + SHIFT + P and select Package Control: Install Package. You can then search for the following plugins that I recommend you use for full-stack Python development:

Anaconda

Anaconda is an extremely powerful Python package for Sublime. It offers:

anaconda

Djaneiro

Djaneiro offers syntax highlighting for Django HTML templates, and tab autocompletion for Django Template Language syntax such as {% block %}{% endblock %}.

Once you have installed Djaneiro, open an HTML file and in the bottom-right corner select the language currently being used, then select Djaneiro -> HTML (Django) to ensure that Django Template syntax highlighting is applied:

Djaneiro syntax highlighting

The tab autocompletion means that you don't have to write out snippets of code over and over again. For example:

A full list of the tab autocompletions in Djaneiro is available here.

SideBar Enhancements

Most importantly, SideBar Enhancements sends files to your Recycle Bin if you delete a file from inside Sublime Text (instead of being sent into oblivion, never to be returned). It also offers a bunch of other features including being able to create new files from the sidebar.

Requirements Txt

This is a simple plugin which offers syntax highlighting for requirements.txt files. Use it!!

requirements.txt syntax highlighting

All AutoComplete

All AutoComplete "extends the default autocomplete to provide autocompletion for all open files".

GitGutter

GitGutter puts a margin into Sublime Text which indicates whether a line has been added, removed or edited. It is useful for tracking whether you have made changes to previous commits.

Other (JavaScript/CSS) Packages

There are a bunch of JavaScript/CSS packages which I also use for my full-stack Python Sublime Text 3 configuration. I won't go into quite so much detail on these, but you should still check them out:

3. Layout

The majority of layout options are available under the view heading in the menu bar.

In Views -> Columns you can switch the view to display 1, 2, 3, or 4 columns, 1 or 2 rows, or a grid of 2 * 2 sections. My preference is to use a 2 column layout.

two column layout sublime text

Other layout preferences that you might want to consider are as follows:

4. Keyboard Shortcuts

It is extremely worthwhile spending a good chunk of time learning the Sublime Text keyboard shortcuts. The shortcuts that I use most frequently are listed below:

HTML specific shortcuts:

View specific shortcuts:

A full list of Sublime Text 3 keyboard shortcuts is available here.

5. Console

When I first started programming in Python I used Enthought Canopy. This has an excellent built-in console IPython console by default. Configuring the console with ST3 is a little trickier, but well worthwhile.

Following this YouTube video, open the command palette using CTRL + SHIFT + P and select install package. Install the SublimeREPL package. Then go to Preferences -> Browse Packages -> SublimeREPL -> Config -> Python. Open the Main.sublime-menu file. Search for "id": "repl_python_run" using CTRL + F and add the option "-i" to the "cmd" section in the "args" below.

Then go to Tools -> Build System -> New Build System and enter the code from this StackOverflow answer:

{
    "target": "run_existing_window_command", 
    "id": "repl_python_run",
    "file": "config/Python/Main.sublime-menu"
}

Save the file as Python-REPL.sublime-build. Then create a simple .py file, select your build system with Tools -> Build System -> Python-REPL and use CTRL + B to run your program. Variables from your program will now be available in the console that appears. Awesome!

What Next?

One small thing that currently irritates me with Sublime is that I can't get the CTRL + / comment/uncomment shortcut to work with .txt and .cfg files. If anybody knows how to do this, please get in touch!