Original address: https://realpython.com/blog/python/setting-up-sublime-text-3-for-full-stack-python-development/
Original title: Setting up Sublime Text 3 for full Stack Python development
Translation: Build an all-purpose python development environment based on sublime text 3
Sublime Text 3 (ST3) is lightweight, Cross-platform code editor known for it speed, ease of use, and strong community sup Port. It's an incredible editor right out of the box, but the real power comes from the ability to enhance its functionality usi NG 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), Enhan Ce the basic functionality with custom themes and packages, and use many of the commands, features, and keyword shortcuts That's make ST3 so powerful.
ST3 is a lightweight, cross-platform code editor known for running speed, ease of use, and strong community support. It's an incredibly out-of-the-box editor, but the ability to enhance itself with Package Manager and custom settings actually ST3 a powerful source of power.
This article will show you how to configure ST3 for full-scale python development (from front to back), enhance basic functionality with custom themes and extensions, and use a number of commands, features, and keyword-based shortcuts to make ST3 very powerful.
This tutorial assumes you ' re using a MAC and is comfortable with the terminal. If you ' re using Windows or Linux, many of the commands would vary, but you should is able to use Google to find the answers Quickly given the info in this tutorial.
This tutorial assumes that you are using a Mac operating system and are skilled at using command-line terminals. Some commands may be different if you're using Windows or a Linux operating system, but you should be able to find out how to use the commands mentioned in this tutorial on your own system using Google.
Before we start, let's address what I mean exactly by "full stack".
In today's world of HTML5 and mobile development, Javascript is literally everywhere. EVERYWHERE. Python coupled with a framework such as Django or Flask are not enough. To really develop a website from end-to-end, you must being 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 being the best programmer you can be, your tools must is sharp. Your development environment must be setup for full stack Development–which it exactly what we were going to does right now ... ..
Before starting this tutorial, let's make it clear what I mean by full stack. JavaScript is widely used in today's HTML5 and mobile device development. everywhere! Python's combination of frameworks such as Django and flask is not enough. To develop an end-to-end Web site, you must familiarize yourself with JavaScript and its numerous JS frameworks, rest APIs, responsive design,html& CSS and others. In order to be the best programmer, 工欲善其事 its prerequisite! You have to configure your development environment to fit all-round development, and that's what we're going to do next.
Features
Let's start by looking at a few of the default features of Sublime Text 3 ...
Split Layouts allow you to arrange your files in various split-screens. This was useful for test driven development (Python code in one screen, test scripts on another) or when working on the fro NT End (HTML on one screens, CSS and/or Javascript on another).
Characteristics
First, let's take a look at sublime. Text 3 provides a list of default features
Split layouts allow you to organize your code with a variety of screen splits. Especially in test-driven development (Python code on one screen, test script in the other) or in the former paragraph development (HTML on one screen, CSS and JS in another) special swimming.
Vintage Mode provides you and VI commands for use within ST3.
- chrome-like Tabs make navigating and editing several files much simpler.
- Automatic loading of the last session re-opens all files and folders your 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 rig HT back up.
Code Snippets Increase your productivity by giving your ability to create common pieces of code with a single Keyword. There is a number of the 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 would 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.
- Vintage mode allows you to use the VI command in ST3
- Chrome-like tags also make it easier to navigate and edit multiple files
- Automatically loads the last session and automatically opens the files and folders that you opened before you last closed st3. The author St3, and open multiple items at the same time, if you restart your computer, open the backed up files and folders immediately
- Snippets allow you to create code snippets with a keyword to improve your efficiency. There are many default code snippets. For example, create a new file, enter Lorem, press the TAB key, You will get a large paragraph of text. If you enter defs in a Python File and tab to a common function body.
customizing Sublime Text 3
After downloading ST3 ...
Install the
subl
Command line tool
Like mate
the command-textmate, Sublime Text includes a command line tool called subl
that allows your to OP En one file, or an entire directory of files and folders, from the terminal.
To enable this command, create a symbolic link to the SUBL binary:
Custom ST3
After downloading ST3
Installing the SUBL command-line tool
Like TextMate's Mate command, sublime text contains a command-line tool called a file or a series of file folders that you can open from a terminal.
To use this command, create a symbolic link to the SUBL library.
$ sudo ln-s/applications/sublime\ text.app/contents/sharedsupport/bin/subl/usr/bin/subl
ensure that the link works by opening Sublime:
Confirm that the link is available by opening sublime
$ subl
If that's didn ' t work, you probably need to add /bin to your Path:
If SUBL does not work, you may need to add/bin to your environment variable
$ echo "Export Path=~/bin: $PATH" >> ~/.profile
Now you can open files and directories using the following command:
# Open the current directory$ subl. # Open a directory called tests$ subl ~/documents/test# open a file called text.txt$ s UBL test.txt
I use the UBUTNU 15.04 to install the ST3 deb package, the command line can be used directly under the SUBL, so this step can be omitted
$ subl hello.py # can be opened directly in sublime without setting
$ SUBL "Hello World" # If there are spaces in the path, the path must be quoted
$ SUBL--help # available to view all commands
Install Package Control
To begin taking advantage of the various packages for extending Sublime ' s functionality, you need to install the package m Anager called package Control –which You must install manually. Once installed, you can use the package Control to install/remove/upgrade all other ST3 packages.
-
To install, copy the Python code for Sublime Text 3 found here. Click View > Show console to open the ST3 console. Paste the code into the console. Press Enter . Reboot ST3.
-
You can now install packages by using the keyboard shortcut cmd+shift+p . Start Typing install until package Control:install package appears. Press Enter and search for available packages.
-
Some Other relevant commands is:
- List Packages shows all your installed Packages
- Remove Packages removes a specific package
- Upgrade Package upgrades a specific package
- upgrade/overwrite all Packages upgrades all your installed Packages
Check out of the official documentation to view more commands.
Install Package Manager in order to take advantage of a variety of packages that extend the sublime functionality, you need to manually install a package manager called Packages control. After installation, you can install/uninstall/upgrade all ST3 packages (plugins).
- In order to install the plugin you must copy the Python code designed for ST3 here. Click view → display console to open the ST3 console, paste the code into the control strip, enter and restart ST3
- You can now install the plugin via Ctrl+shift+p. Press the shortcut key and enter instal until the package control:install . Hit enter and search for available plugins.
- Some of the other commands include
- List the plugins you have installed
- Remove a specific plug-in
- Upgrade a specific plugin
- Upgrade/Overwrite all packages to upgrade all your plugins
View official documents documentation get more commands.
Create a Custom Settings File
You can fully configure Sublime Text using json-based settings files, making it easy to transfer, or synchronize, your Cus tomized settings to another system. First, we need to create our customized settings. It's best-to-create a base file for any environments as well as language-specific settings files.
To set up a base file click Sublime Text > Preferences > Settings–user. Add an empty JSON object to the file and add your settings:
Creating a new custom configuration file
You can configure the file freely in JSON format sublime text, in JSON format makes the configuration file easy to transfer, or sync your configuration to other systems. First we need to create our own custom settings. It is recommended that you set up basic profiles and language-specific profiles for all environments, respectively.
Create a basic configuration with sublime text→ options → configuration-user. Add an empty JSON object to the file, and add the configuration
{ //Base settings "Auto_complete": false, "Sublimelinter": false, "Tab_size": 2, "Word_wrap": True
- Language-specific configuration,Sublime Text > Preferences > Settings–more > Syntax specific–use, with language name. Sulime-settings to save, such as needles The configuration file for Python is python.sublime-settings
- You can make any configuration of St, but I strongly recommend you start with configuring the basic configuration and the configuration for Python, and you'll see the changes
- Optional: You can use Dropbox to sync all your configurations, upload files to Dropbox, and load and sync the sublime environment on all your computers.
- A good sublime configuration reference sublime Text unofficial documentation.
Themes
ST3 also gives you the option to change the overall theme to better suit your personality. Design your own. Or, if you ' re not artistically inclined, you can download one of the various custom themes designed by the Sublime Communi Ty through package Control. Check out colorsublime to preview themes before installing them.
The ever popular Soda Dark Theme and the minimal flatland are both of my personal favorites.
After installing a theme, make sure to update your base settings, Sublime Text > Preferences > settings–user :
Packages
In addition to the packaged themes, I also use these plugins to add speed to my workflow.
Sidebarenhancements Side Bar Enhancements
sidebarenhancements extends the number of the menu options in the sidebar and speeding up your overall. Options such as "New file" and "Duplicate" are essential and should is part of ST3 out of the box. The "Delete" option alone makes it worth downloading. This feature simply sends files to the Trash, which could seem trivial if you delete a file without it, it ' s very diffic Ult to recover unless you ' re using a version control system.
This plugin expands the number of sidebar books and accelerates the workflow you don't work with. For example, new and duplicated are the basic options for ST3, and the "delete" option makes the plugin worth downloading. This feature puts the file into the Recycle Bin that doesn't look very important, but you don't have to delete the file with this option, Unless you're using a version control system, it's hard to recover files.
Anaconda
Anaconda is a flagship Python plugin that adds a series of IDE-like features to ST3, such as:
You can view all of the features here, or within the README file in ST3 's package Settings: Sublime Text > Preferen CES > Package Settings > Anaconda > Readme. Click on the link to view all features, or view the Readme file.
Sublimecodeintel is another popular package, which have many of the same features as Anaconda. I suggest testing them both out.
This plugin is another very popular plugin, there are a lot of similar features and Anaconda, it is recommended that you all try.
Djaneiro
Djaneiro supports Django templating and keyword highlighting and provides useful code snippets (tab completions) For Sublime Text. The snippet system is an incredible timesaver. You can create common Django blocks with only a few keystrokes for templates, models, forms, and views. Check out the official documentation to see a list of snippets.
My Personal favorites is for templating: var
creates {{ }}
and tag
creates{% %}
Requirementstxt
requirementstxt provides autocompletion and syntax highlight-lighting as well as a nice version management system For your requirements.txt files.
Sublimelinter
Related reading: http://segmentfault.com/a/1190000000389188 learn to use sublime plugin Sublimelinter
Sublimelinter is a framework for ST3 Linters. The package itself does does include any actual linters; Those must is installed separately via package Control using the sublimelinter-[linter_name] naming syntax. You can view official linters here. There is also a number of third party linters, which can is viewed in the package Control. Check out the installation instructions here.
Sublimelinter is a ST3 code-checking framework. The plug-in itself does not contain any inspectors. You must specify the syntax through the plug-in Manager Sublimelinter-[linter_name]. Click on the link to view all official inspectors. You can also try a third-party checker, The Plugin Manager force is available for viewing. Click on the link to view the installation instructions
For Python linting, I recommend using sublimelinter-pyflakes and sublimelinter-pep8.
For Python code checking, sublimelinter-pyflakes and SUBLIMELINTER-PEP8 are recommended
I also use sublimelinter-jshint, sublimelinter-pyyaml, sublimelinter-csslint, Sublimelinter-html-tidy, and Sublimelinter-json.
Most of these linters has dependencies associated with them, so please read the installation instructions before Installi Ng.
You can customize all linter in the user-defined sublimelinter.sublime-settings file: sublime Text > Pref Erences > Package Settings > Sublimelinter > Settings–user. For example, I ignore the following PEP8 errors and warnings: Methods for customizing errors
"Pep8": { "@disable": false, "args": [], "excludes": [], "Ignore": "e501,c0301,w0142,w0402,r0201, e1101,e1102,c0103,r0901,r0903,r0904,c1001,w0223,w0232,w0201,e1103,r0801,c0111 ", " max-line-length ": 100, "Select": ""},
Gitgutter
gitgutter shows little icons in ST3 's gutter area the indicate whether a line has been inserted, modified, or de Leted since the last commit. Gitgutter is a plug-in that is compatible with sublime text 2 or sublime text 3, which can be displayed before the number of lines in the line is incremented, modified, or deleted. Displays the plug-in for each line change.
Emmet
Emmet, previously known as Zen Coding, uses simple abbreviations to generate HTML or CSS code snippets.
For example, if you type a bang, then press TAB in an !
HTML file, the HTML5 doctype and a few basic tags is generat Ed
<!doctype Html>lang= "en" > < Meta charset= "UTF-8" > <title>document</title><body></ Body></HTML> |
Check out the official documentation as well as this is handy cheat sheet for more info.
Translation: Build an all-purpose python development environment based on sublime Text 3