Setting up Sublime Text 3 for Full Stack Python Development

-

Affiliate Disclosure: Every purchase made through our affiliate links earns us a pro-rated commission without any additional cost to you. Here are more details about our affiliate disclosure.

Sublime Text 3 (ST3) is lightweight, cross-platform code editor known for its speed, ease of use, and strong community support. It’s an incredible editor right out of the box, but the real power comes from the ability to enhance its functionality using Package Control and creating custom settings.

In this article, we’ll look at how to setup Sublime Text for full stack Python development (from the front to back), enhance the basic functionality with custom themes and packages, and use many of the commands, features, and keyword shortcuts that make ST3 so powerful.

Before start discussing about Sublime Text 3, first you should know, What should you look for in a Python Code Editor. Follow the link below

WHAT SHOULD YOU LOOK FOR IN A PYTHON CODE EDITOR?

Subline

In today’s world of HTML5 and mobile development, Javascript is literally everywhere. EVERYWHERE. Python coupled with a framework such as Django or Flask is not enough. To really develop a website from end-to-end, you must be familiar with Javascript (and the various Javascript frameworks), REST APIs, responsive design, and of course HTML and CSS, among others. And let’s face it: Like any craftsman, in order to be the best programmer you can be, your tools must be sharp. Your development environment must be set up for full stack development – which is exactly what we are going to do right now…

Features of Sublime Text 3

Let’s start by looking at a few of the default features of Sublime Text 3…

  1. Split Layouts allow you to arrange your files in various split-screens. This is useful for test-driven development (Python code on one screen, test scripts on another) or when working on the front end (HTML on one screen, CSS and/or Javascript on another).
  2. Vintage Mode provides you with vi commands for use within ST3.
  3. Chrome-like Tabs make navigating and editing several files much simpler.
  4. Automatic loading of the last session re-opens all files and folders you had open when you closed the editor the last time. I leave ST3 open all the time, with various projects open – so if I reset the computer, it opens the files and folders right back up.
  5. Code Snippets increase your productivity by giving you the ability to create common pieces of code with a single keyword. There are a number of default snippets. For example, open a new file and type in “lorem” then press tab. You should get a paragraph of lorem ipsum text. Also, if you type “defs” then press tab in a Python file it will setup a generic function. You can also create your own snippets: Tools > New Snippet. Refer to the documentation for help, and also check out some of my snippets here.

Customizing Sublime Text 3

After downloading ST3 …

Font choice

Ubuntu Mono is a great font. I’ve switched from primarily using Menlo a few days ago and I’m not regretting it so far. With Ubuntu Mono, I find font size 16 very comfortable to read.

Installed plug-ins

As mentioned before, Sublime has a very extensive plug-in ecosystem. I’m currently using the following plug-ins:

  • Package Control A package manager for installing additional plug-ins directly from within Sublime. This should be the only package you have to install manually. All other packages listed here can be installed via Package Control. It’s also possible to update installed packages with Package Control. Simply think of it as the apt-get of Sublime packages.
  • Color Scheme – Tomorrow Night Color schemes determine the font colors used for syntax highlighting in the editor view. Tomorrow is a nice dark color scheme.
  • Theme – Soda Dark Themes change the color and style of Sublime’s UI elements. This one fits perfectly with the Tomorrow color scheme.
  • SideBarEnhancements This plug-in provides additional context menu options in the sidebar, such as “New file” or “New Folder”. These should be in there by default, but they are not.
  • All Autocomplete Sublime’s default autocomplete only considers words found in the current file. This plug-in extends the autocomplete word list to find matches across all open files.
  • SublimeCodeIntel Enhances autocomplete for some languages including Python. The plug-in also lets you jump to symbol definitions across files by pressing alt and then clicking on a symbol. Very handy.
  • SublimeREPL Allows you to run a Python interpreter session in an editor view. I tend to use bpython in a separate terminal window but sometimes SublimeREPL is helpful.
  • GitGutter Adds little icons to the editor’s gutter area indicating whether a line has been inserted, modified, or deleted according to Git. To get colored icons update your color scheme file as instructed in the GitGutter readme.
  • Pylinter This plug-in provides the best pylint editor integration I’ve seen so far. It automatically lints .py files whenever they’re saved and displays pylint violations directly in the editor view. It also has a convenient shortcut that locally disables a pylint check by inserting a #pylint: disable comment. This plug-in sealed the deal for me.

Preferences files

One of the nice things about Sublime Text 3 is that it can be completely configured using simple JSON-based preferences files. This allows you to easily transfer your settings to another system. I’ve also seen people use Dropbox to automatically synchronize their settings on every computer they’re using.

Preferences.sublime-settings configures Sublime’s look-and-feel and its built-in behavior. You can open the prefs file for editing within Sublime via Preferences > Settings – User. I’m using the following settings:

{
    // Colors
    "color_scheme": "Packages/Tomorrow Color Schemes/Tomorrow-Night.tmTheme",
    "theme": "Soda Dark.sublime-theme",

    // Font
    "font_face": "Ubuntu Mono",
    "font_size": 16.0,
    "font_options": ["subpixel_antialias", "no_bold"],
    "line_padding_bottom": 0,
    "line_padding_top": 0,

    // Cursor style - no blinking and slightly wider than default
    "caret_style": "solid",
    "wide_caret": true,

    // Editor view look-and-feel
    "draw_white_space": "all",
    "fold_buttons": false,
    "highlight_line": true,
    "auto_complete": false,
    "show_minimap": false,
    "show_full_path": true,

    // Editor behavior
    "scroll_past_end": false,
    "highlight_modified_tabs": true,
    "find_selected_text": true,

    // Word wrapping - follow PEP 8 recommendations
    "rulers": [ 72, 79 ],
    "word_wrap": true,
    "wrap_width": 80,

    // Whitespace - no tabs, trimming, end files with \n
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "ensure_newline_at_eof_on_save": true,

    // Sidebar - exclude distracting files and folders
    "file_exclude_patterns":
    [
        ".DS_Store",
        "*.pid",
        "*.pyc"
    ],
    "folder_exclude_patterns":
    [
        ".git",
        "__pycache__",
        "env",
        "env3"
    ]
}

Pylinter.sublime-settings configures the pylinter plug-in. I use the following settings to lint Python files automatically on save and to display graphical icons for lint violations:

{
    // Configure pylint's behavior
    "pylint_rc": "/Users/daniel/dev/pylintrc",

    // Show different icons for errors, warnings, etc.
    "use_icons": true,

    // Automatically run Pylinter when saving a Python document
    "run_on_save": true,

    // Don't hide pylint messages when moving the cursor
    "message_stay": true
}

Key bindings

Sublime’s key bindings are also fully user-configurable via JSON-based sublime-keymap preferences files. I’ve made a few changes to the default bindings to better serve my existing TextMate/IntelliJ muscle memory. You may not need to make changes to the key bindings at all. But if you want to, modifying them is very easy and transferable across platforms. I use the following additional key bindings:

[
    // Rebind "go to file" to cmd+shift+O
    { "keys": ["super+shift+o"], "command": "show_overlay", "args": {
        "overlay": "goto",
        "show_files": true
    }},

    // Rebind swap line up/down to cmd+shift+up/down
    { "keys": ["super+shift+up"], "command": "swap_line_up" },
    { "keys": ["super+shift+down"], "command": "swap_line_down" },

    // Delete a line with cmd+delete
    { "keys": ["super+backspace"], "command": "run_macro_file", "args": {
        "file": "Packages/Default/Delete Line.sublime-macro"
    }},

    // Reindent selection with cmd+alt+L
    { "keys": ["super+alt+l"], "command": "reindent"}
]

Command line tools

Similarly to TextMate’s mate, Sublime Text 3 includes a command line tool that allows you to open the editor from the shell. The tool called subl is not enabled by default. To make it available from any shell do the following:

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

To use Sublime Text 3 as the default editor for interactive Git commands, for example when composing commit messages, add the following line to your ~/.profile:

export GIT_EDITOR="subl --wait --new-window"

Conclusion

I hope this article was helpful to you and that you were able to integrate some of the above packages and custom settings along with your own based on your personal preferences to improve your workflow. If you have any comments or suggestions of your own, please let me know in the comments below. Finally, check out the dotfiles folder in this repo to view all resources that I created.

Cheers!

Related Articles

Like our Article/ Blog? Can buy a Buttermilk for our team.. Click here

Pardeep Patelhttps://pardeeppatel.com/
Hi!, I am Pardeep Patel, an Indian passport holder, Traveler, Blogger, Story Writer. I completed my M-Tech (Computer Science) in 2016. I love to travel, eat different foods from various cuisines, experience different cultures, make new friends and meet other.

Share this article

-- Advertisement --

LEAVE A REPLY

Please enter your comment!
Please enter your name here

-- Advertisement --