Ultimate Sublime for Python

Ultimate Sublime for Python

https://medium.com/@sumeetsarkar/ultimate-sublime-for-python-5c531224421b

Development productivity is a function of development convenience.

Photo by Chris Ried on Unsplash

Developers are a bunch of opinionated jarheads. Hence, I keep this article open ended for each of you to comment on what your ultimate development setup for Python shapes out like.

TLDR person? Jump to setup

Audience

I am sure each one of us have used sublime some or the other time in our workflow. Some may already be a power user of sublime since version 1. This article is focussed towards setting up an ultimate python development setup in sublime text 3 for those who may or may not been leveraging sublime to its fullest potential.

Some Pretext…

I have been a big VSCode fan. I fully depend on it for Javascript projects. When it came to python development, I started with VSCode straight up. I like VSCode’s no nonsense, clean, beautiful and plugin approach to development setup. But soon I realised there was a big problem. Searching symbols in large workspaces accurately and even within a file, and on top of it, it was slow! Yes I did install ctags, but it couldn’t keep you less frustrated. Some how with python it sucked. I was torn by the idea to part my ways from VSCode.

Long back, I have used Intellij Idea for Android and Java projects and was often blown away by its wholistic approach towards development, with its one place to do everything. But somehow, there were just too many configurations thrown upfront, so many GUI elements to interact with, it never failed to distract. And the constant pressure of being torn unless toggling each configuration to see if it suites my workflow was too much to handle! My fellow OCD friends might agree?

Still I decided to try out PyCharm. Though it has one of the best symbol searches, for the reasons mentioned earlier, I could not take it up.

Sublime

Fascinated by absolute minimalistic approach in Sublime? I was, but unfortunately so far I used it only for few scripting programs.

One thing i appreciated about both VSCode and Sublime was settings as JSON, and default and user settings. However, recent VSCode versions are taking it up more like Intellij IDEs.

See, JSON settings are brilliant. We can write our comments in settings as to why we want a particular setting, why we disabled it in the first place. It is like having your settings just look like your regular code, this is what less distraction for developer means!

And the symbol search for python in workspace or file? Two words.

Blazing Fast!

The Setup

Assuming you are having a barebones sublime text 3, here are the below setup steps.

Package control

There cannot be enough stressing this point, firstly install package control. It is the best way to perform package management in sublime. Once installed, you can simply install/ uninstall your packages from sublime package repository seamlessly.

Sidebar enhancements

Sublime is minimal. Install sidebar enhancements to allow a plethora of operations on files and folders in sidebar.

Anaconda

Turn your sublime into a fully featured Python IDE, with autocompletions, linting, autopep8 formatting, search for references and much more.

My Anaconda user settings. I use sublime linter for linting, hence disabled it in anaconda.

{
    /*
        No Autoformatting
    */
    "auto_formatting": false,
    "autoformat_ignore":
    [
        "E309",
        "E501"
    ],
    "pep8_ignore":
    [
        "E309",
        "E501"
    ],
    /*
        No Linting (this is done by sublinter-flake8)
    */
    "anaconda_linting": false,
    "anaconda_linter_underlines": false,
    "anaconda_linter_mark_style": "none",
    "display_signatures": true,
    /*
        Use anaconda for code completion
        Suppress sublime completions
    */
    "disable_anaconda_completion": false,
    "suppress_word_completions": true,
    "suppress_explicit_completions": true,
    /*
        Others
    */
    "complete_parameters": false
}

As in the above settings, suppress the sublime completions and anaconda never fails to amuse how smartly it picks up near accurate auto completions and find references to a symbol.

Function documentation by anaconda

Go to Definition

Install go to definition to quickly drill down to code definitions

Sublime linter

I prefer linting my python code with sublime linter. This has few steps to it.

  1. Install flake8 pip install flake8
  2. Install SublimeLinter from package control
  3. Install SublimeLinter-flake8

My SublimeLinter user settings

// SublimeLinter Settings - User
{
    "show_panel_on_save": "never",
"gutter_theme": "Packages/Theme - Monokai Pro/Monokai Pro.gutter-theme",
    "styles": [
        {
            "mark_style": "outline",
            "priority": 1,
            "scope": "region.orangish",
            "icon": "warning",
            "types": [
                "warning"
            ]
        },
        {
            "mark_style": "squiggly_underline",
            "priority": 1,
            "scope": "region.redish",
            "icon": "error",
            "types": [
                "error"
            ]
        }
    ]
}

Sublime linter warns you with non compliant flake8 code warnings (see orange outline) and errors (see red squiggly underline).

The colours provide a quick visual intimation. Or else you may hover to view the error/ warning, or completely pull up the linting console window with a shortcut to view all the errors, in current or only opened or all files in workspace.

Notice the status bar with flake8(1|1) i.e., 1 warning and 1 error. Cool!

GitGutter

Instantly see inserted, modified, deleted lines in a git project in the gutter with configurable icons. It also has a popup view showing the diff made and few operations to revert etc, if you are into that level of interaction in GUI. It also displays the info in the status bar.

My GitGutter user settings

// GitGutter Settings - User
{
    "theme": "Monokai Pro.gitgutter-theme",
    "protected_regions": [
        "sublimelinter-warning-gutter-marks",
        "sublimelinter-error-gutter-marks",
        "sublime_linter.protected_regions"
    ]
}

Python Breakpoints

Quickly toggle breakpoints, goto breakpoints, select custom debugger of your choice, pdb, pudb etc.

Terminal

Open terminal for current file path or workspace with a simple shortcut. If you are an iTerm person like me, that is also configurable.

{
 "terminal": "iTerm2-v3.sh",
   "parameters": ["--open-in-tab"]
}

Isort

Install Isort to sort python imports. Invoke from command palette and quickly sort imports in current file. It really becomes handy.


Color scheme

Programming is an Art, so why not play with colours?

No setup is complete, without a spot on colour scheme. I am very finicky about the colour scheme, font size and font style. There are many colour schemes which really standout. The always evergreen Monokai to Draculaand Tomorrow Night. But my favourite in recent times is Monokai Pro!

Monokai Pro may have designed the best colour palette ever.

Shamelessly lifting of the colour palette screenshot from Monokai article in medium Do read this!

I use Monokai Pro Machine most often (the theme/ color scheme set in the screenshots above)


Finally, I have a small set of optimised keyboard shortcut settings, for most frequent operations. Do not judge! :D

[
 { "keys": ["super+d"], "command": "duplicate_line" },
 { "keys": ["super+k","super+z"], "command": "toggle_distraction_free" },
 { "keys": ["super+o"], "command": "goto_symbol_in_project" },
 { "keys": ["super+["], "command": "jump_back" },
 { "keys": ["super+]"], "command": "jump_forward" },
 { "keys": ["super+alt+down"], "command": "goto_definition" },
 { "keys": ["super+alt+shift+down"], "command": "goto_reference" },
 { "keys": ["super+shift+o"], "command": "prompt_open" },
]

Comment me below with your favourite setups!

猜你喜欢

转载自blog.csdn.net/ultrapro/article/details/84839137