Setting up the Python development environment for Sublime Text

Source: Internet
Author: User
Tags sublime text
Recently, when I mostly used the Python development environment to edit, I began to use Sublinme Text 2 more and more. This article focuses on making Python programmers use some of the more convenient settings and tweaks.

Why Choose Sublime Text?

I used to be a loyal user of textmate. This is a lightweight, open source software that is native to OS X and has a good Mac style. However, although TextMate is a great editor, sometimes it seems to be not functional enough.

I've used some of the more powerful software, such as IntelliJ idea, which adds a Python plugin. I particularly like its debugger and test runner. However, a full-featured IDE like IntelliJ is too large for small and medium-sized projects.

I've been using Sublime Text more and more in recent weeks. When I installed it, it felt very good. It's really very fast, automatic periodic updates, and even better is full support across platforms. For me, it is ultimately better than textmate where the sublime is a powerful plug-in subsystem. For Python development, there are a number of plugins that will make your development smoother and more enjoyable.

I'm still switching the editor between different projects. But I found that with Python development, Sublime has a good balance between a lightweight editor and a full-featured IDE.

Selection of fonts

Ubuntu Mono is a very, very nice font. The other day I just switched over from Menlo, which is absolutely not to be regretted.

On my 15-inch MacBook, Ubuntu Mono's number 16th is perfect. 1680x1050 resolution for a sidebar plus two editor windows (automatically adjusted to 80 characters justifies) just right.

If you plan to carefully select the font, slant.co this article is very good. It contains most of the popular programming aspects of font and download links.

Installing plugins

As mentioned earlier, Sublime has a very rich plug-in system. I am currently using the following plugins:

The package control installs the add-in Bundle manager directly in the Sublime. This is the only plugin you have to install manually. All other plugins listed here can be installed through the package Control. You can also use it to update installed plugins. Simply want to do is Sublime packages apt-get on the line.

Color Scheme-tomorrow night color schemes determines the font color of the editor interface Syntax highlighting. This is a very cool dark line style.

Theme-soda Dark Themes affects the color and style of the Sublime interface elements. This is a perfect color scheme for tomorrow night.

Sidebarenhancements This plugin provides additional contextual menu options for the sidebar, such as "New File", "New Floder", and so on. These should have been the default, but not.

All Autocomplete Sublime The default AutoComplete only focuses on the words of the current file. This plugin expands its AutoComplete word list to all open files.

Sublimecodeintel enhances auto-completion for some languages, including Python. This plugin also allows you to jump to the definition of the symbol, by holding down ALT and clicking on the symbol. Very convenient.

SUBLIMEREPL allows you to run the Python interpreter directly from the editing interface. I tend to run with Bpython in a separate terminal window, but sometimes sublimerepl is helpful.

Gitgutter in the Groove area of the editor, according to Git, add small icons to identify whether a row has been inserted, modified, or deleted. In Gitgutter's readme, there are instructions on how to change the color icon to update your color scheme file.

Pylinter This plugin provides the best pylint editor integration I've ever seen. It automatically checks the. py file whenever it is saved and displays the Pylint violation directly in the editing interface. It also has a shortcut to disable the partial pylint check by inserting a #pylint: disables the comment. This plugin is really useful for me.

Configuration file

One advantage of Sublime Text is that all of its configurations are simple JSON-based configuration files. This allows you to easily move the configuration to another system. I've seen some people use Dropbox to automatically sync the configuration on all their computers.

The preferences.sublime-settings configures the display and behavior of the Sublimede. You can open and edit this file in sublime by Preferences > Settings-user. I use the following configuration:

{//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_b Old "]," Line_padding_bottom ": 0," Line_padding_top ": 0,//Cursor style-no blinking and slightly wider than D    Efault "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,//Editor be Havior "Scroll_past_end": false, "Highlight_modified_tabs": True, "Find_selected_text": true,//Word Wrappi  Ng-follow PEP 8 Recommendations "rulers": [[], "word_wrap": True, "Wrap_width": $,//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 configuration of the Pylinter plugin. I use the following configuration to let Pyhton automatically spec when saved and display icons for violations of the specification.

{    //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 hi De pylint messages when moving the cursor    "Message_stay": true}

Key Bindings

The Sublime key binding is also a fully configurable JSON-based Sublime-keymap configuration file. I modified some of the default configurations to better match my textmate/intellij muscle memory. You can not modify it at all. If you want, the modifications are simple and can be used across platforms. I use the following bindings:

[    //Rebind ' go to file ' to Cmd+shift+o    {"Keys": ["Super+shift+o"], "command": "Show_overlay", "args": {        "ove Rlay ":" 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": "Pac Kages/default/delete line.sublime-macro "    }},      //reindent selection with cmd+alt+l    {" Keys ": [" super+ Alt+l "]," command ":" Reindent "}]

Command-line tools

Similar to TextMate mate, Sublime Text contains a command-line tool that allows you to open the editor through the shell. The tool name is Sublis and is not available by default. To make it effective, run the following in either Shell:

Ln-s/applications/sublime\ text\ 2.app/contents/sharedsupport/bin/subl/usr/local/bin/subl

To use Sublime as the default editor for git interactive commands-for example, to compose submissions-simply add the following line to your ~/.profile file:

Export git_editor= "Subl--wait--new-window"

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.