4. Mac下配置Sublime Text3 python及conda開(kāi)發(fā)環(huán)境

Table of Contents

1.?Features

2.?Customizing Sublime Text 3

? ? ? ? 2.1 Install the subl command line tool

? ? ? ? 2.2 Install Package Control

? ? ? ? 2.3 Create a Custom Settings File

3.?Themes

4.?Packages

? ? ? ? 4.1 SideBarEnhancements

? ? ? ? 4.2 Anaconda

? ? ? ? 4.3 Djaneiro

? ? ? ? 4.4 requirementstxt

? ? ? ? 4.5 SublimeLinter

????????4.6?GitGutter

????????4.7?FTPSync

? ? ? ? 4.8 AdvancedNewFile

? ? ? ? 4.9 Emmet

? ? ? ? 4.10 Markdown Preview

5.?Keyboard Shortcuts

6.?Custom Commands

7.?Additional Resources

8.?Conclusion

Sublime Text 3?(ST3) is a 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 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.

Note:?This tutorial assumes you’re using a Mac and are comfortable with the terminal. If you’re using Windows or Linux, many of the commands will vary, but you should be able to use Google to find the answers quickly given the info in this tutorial.

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 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, and so on.

Let’s face it: as a programmer, you are like any other craftsman. If you want to be the best you can be, then you need your tools to be sharp. Your development environment must be set up for full stack development—which is exactly what we are going to do right now.

Free Bonus:?5 Sublime Text Tweaks to Boost Your Python Productivity, a free email class that shows you how to optimize your Python + Sublime development setup for maximum efficiency.

Features

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 when you are doing test driven development (Python code on one screen, test scripts on another) or 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. To try one for yourself, open a new file, type in?lorem, and press?Tab. You should get a paragraph of lorem ipsum text. Also, if you type?defs?and then press?Tab?in a Python file, it will setup a generic function.

Note:?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 you download ST3, you can customize it.?

Install the?subl?command line tool

Just Like TextMate has the?mate?command, Sublime Text has a command line tool called?subl?that allows you to open 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:

$ sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl

Ensure that the link works by opening Sublime:

$ subl

If that didn’t work, you probably need to add?/bin?to your path:

$ echo "export PATH=~/bin:$PATH" >> ~/.profile

Then repeat step one.

Note:?If you are still having trouble, check out?this article?for help. You can also read up on creating the symbolic links in?Windows?and?Linux.

Now you can open a file or directory using the following commands:

# Open the current directory.

$ subl .

# Open a directory called tests.

$ subl ~/Documents/test

# Open a file called text.txt.

$ subl test.txt

If there are spaces in the path, you must surround the entire path in double quotes:

$ subl "~/Documents/test/my test file.txt"

To view all the commands, open up the help file:

subl --help


這里我用的另一種方法:

添加命令行別名

打開(kāi)用戶配置文件.zshrc

aliass ubl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"

#如果不添加別名,也可以選擇將路徑添加到環(huán)境變量下。

#這里的路徑根據(jù)實(shí)際情況可能會(huì)有所不同挥转。

wq保存后回到命令行執(zhí)行以下命令使其生效:

source~/.zshrc

Install Package Control

To begin taking advantage of the various?packages?for extending Sublime’s functionality, you need to manually install the package manager called Package Control. Once you have it installed, you can use it to install, remove, and upgrade all other ST3 packages.

? ? 1. 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.

? ? 2. 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.

Here are some other relevant commands:

????List Packages?shows all your installed packages.

????Remove Package?removes a specific package.

????Upgrade Package?upgrades a specific package.

????Upgrade/Overwrite All Packages?upgrades all your installed packages.

Check out the official?documentation?to view more commands.

Create a Custom Settings File

You can fully configure Sublime Text using JSON-based settings files, so it’s easy to transfer or synchronize your customized settings to another system. First, we need to create our customized settings. It’s best to create a base file for all 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 like so:

{

? ????// base settings

? ????"auto_complete": false,

? ????"sublimelinter": false,

? ????"tab_size": 2,

????? "word_wrap": true

}

1. For language specific settings, click?Sublime Text > Preferences > Settings - More > Syntax Specific - User. Then save the file using the following format:?LANGUAGE.sublime-settings. For Python-specific settings, save the file as?Python.sublime-settings.

2. You can obviously configure your settings to your liking. However, I highly recommend starting with my?base?and?Python-specific?settings and then making changes as you see fit.

3. Optional: You can use Dropbox to sync all your settings. Simply upload your settings files to?Dropbox?and load them from there to sync the Sublime environments on all your machines.

4. A good reference for settings can be found at the?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 community through Package Control. Check out?ColorSublime?to preview themes before installing them.

The ever popular?Soda Dark Theme?and the minimal?Flatland?are two of my personal favorites.

After installing a theme, make sure to update your base settings through?Sublime Text > Preferences > Settings - User:

{

? ????"theme": "Flatland Dark.sublime-theme",

????? "color_scheme": "Packages/Theme - Flatland/Flatland Dark.tmTheme"

}

Packages

Besides the packaged themes, I take advantage of the following packages to speed up my workflow.

SideBarEnhancements

SideBarEnhancements?extends the number of menu options in the sidebar, speeding up your overall workflow. Options such as?New File?and?Duplicate?are essential and should be part of ST3 out of the box. The?Delete?option alone makes it worth downloading. This feature simply sends files to the Trash, which may seem trivial, but if you delete a file without it, then it’s very difficult to recover unless you’re using a version control system.

Download this now!

Anaconda

Anaconda?is the ultimate Python package. It adds a number of IDE-like features to ST3 including the following:

? ??1. Autocompletion?works by default, but there are a number of configuration?options.

? ??2. Code?linting?uses either PyLint or PyFlakes with PEP 8. I personally use a different linting package, as I will explain shortly, so I disable linting altogether within the user-defined Anaconda settings file,?Anaconda.sublime-settings, via the file menu:?Sublime > Preferences > Package Settings > Anaconda > Settings - User:?{"anaconda_linting": false}

? ??3. McCabe code complexity checker?runs the?McCabe complexity checker?tool within a specific file. If you’re not familiar with what complexity is, be sure to visit the link above.

? ??4. Goto Definitions?finds and displays the definition of any variable, function, or class throughout your entire project.

? ??5. Find Usage?quickly searches where a variable, function, or class has been used in a specific file.

? ??6. Show Documentation?shows the docstring for functions or classes (if defined, of course).

You can view all of the features?here?or within the README file in ST3’s Package Settings:?Sublime Text > Preferences > Package Settings > Anaconda > README.

Note:?SublimeCodeIntel?is another popular package that has many of the same features as Anaconda. I suggest testing them both out.

Djaneiro

Djaneiro?supports Django templating and keyword highlighting and provides useful code snippets (tab completions) for Sublime Text. The snippet system is an incredible time-saver. 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 are for templating:?var?creates?{{ }}?and?tag?creates?{% %}.

requirementstxt

requirementstxt?provides autocompletion and syntax highlighting as well as a nice version management system for your?requirements.txt?files.

SublimeLinter

SublimeLinter?is a framework for ST3 linters. The package itself does not include any actual linters; those must be installed separately via Package Control using the?SublimeLinter-[linter_name]?naming syntax. You can view official linters?here. There are also a number of third party linters, which can be viewed in Package Control. Check out the installation instructions?here.

For Python linting, I recommend using?SublimeLinter-pyflakes?and?SublimeLinter-pep8.

I also use?SublimeLinter-jshint,?SublimeLinter-pyyaml,?SublimeLinter-csslint,?SublimeLinter-html-tidy, and?SublimeLinter-json.

Note:?Most of these linters have dependencies associated with them, so please read the installation instructions before installing.

You can customize each linter in the user-defined?SublimeLinter.sublime-settings?file:?Sublime Text > Preferences > Package Settings > SublimeLinter > Settings - User. For example, I ignore the following PEP 8 errors and warnings:

"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 that indicate whether a line has been inserted, modified, or deleted since the last commit.

Note:?If you want support for a number of distributed version control systems (Git, SVN, Bazaar, and Mercurial), check out?Modific.

FTPSync

FTPSync?syncs your project with your remote files. Simply open the file to download it (if the remote file is newer than your local file) and upload it to your remote server with every save. That’s a great way to keep your local and remote(s) in sync. You’ll want to make sure to add at least one remote connection by clicking?Sublime Text > Preferences > Package Settings > FTPSync > Setup FTPSync.

Sample settings:

{

? "primary": {

? ? host: "ftp.mywebsite.com",

? ? username: "johnsmith",

? ? password: "secretpassword",

? ? path: "/www/",

? ? upload_on_save: true,

? ? tls: true

? }

}

I personally set the password to?null?because I don’t want it visible in that file. FTPSync just asks for my password after each save.

AdvancedNewFile

AdvancedNewFile?is used to create a new folder or file from within ST3 with key bindings alone.

Simply bring up the AdvancedNewFile input through the appropriate key binding. Then, enter the path, along with the file name into the input field. Upon pressing?Enter, the file will be created. In addition, if the directories specified do not yet exist, they will be created. By default, the path to the file being created will be filled shown in the status bar as you enter the path information.

For a more detailed explanation on its usage, check out the documentation on?GitHub. Be sure to read about Tab Completion as well as Predefined Aliases.

I replaced the normal?Cmd+N?command to create a new file with AdvancedNewFile by adding the following code to the?Key Bindings - User?file:?Sublime Text > Preferences > Package Settings > AdvancedNewFile > Key Bindings - User:

[

? { "keys": ["cmd+n"], "command": "advanced_new_file_new"}

]

You can also setup a default directory to start with:?Sublime Text > Preferences > Package Settings > AdvancedNewFile > Settings - User

{"default_initial": "/Users/michaelherman/Documents/repos"}

Now when I create a new file, the?/Users/michaelherman/Documents/repos?string is automatically inserted first, since 99% of the time I store all my scripts in that directory.

Emmet

Emmet, previously known as Zen Coding, uses simple abbreviations to generate HTML or CSS code snippets.

For example, if you type a bang,?!, and press?Tab?in an HTML file, then the HTML5 doctype and a few basic tags will be generated:

<html lang="en">

<head>

? <meta charset="UTF-8">

? <title>Document</title>

</head>

<body>

</body>

</html>

Check out the official?documentation?as well as this handy?cheat sheet?for more info.

Markdown Preview

Markdown Preview?is used for previewing and building markdown files.

To use, open the Package Manager and type?Markdown Preview?to show the available commands:

????Markdown Preview: Python Markdown: Preview in Browser

????Markdown Preview: Python Markdown: Export HTML in Sublime Text

????Markdown Preview: Python Markdown: Copy to Clipboard

????Markdown Preview: GitHub Flavored Markdown: Preview in Browser

????Markdown Preview: GitHub Flavored Markdown: Export HTML in Sublime Text

????Markdown Preview: GitHub Flavored Markdown: Copy to Clipboard

????Markdown Preview: Open Markdown Cheat Sheet

Once converted, the output file will be updated on each subsequent save.

Keyboard Shortcuts

Goto Anything?Cmd+P?is used for quickly finding and opening files. Just type in a part of a path and filename within a project and you can easily open that file. This is great for quickly opening files in large Django projects.

Goto Line Number?Ctrl+G?takes you to a specific line number in an active file.

Goto Symbol?Cmd+R?lists all functions and classes within a file to make them easier to find. Simply start typing the one you want.

Go to beginning of line?Cmd+Left?and?Go to end of line?Cmd+Right?help you navigate within lines.

Delete current line?Ctrl+Shift+K?deletes the current line.

Multi-Edit?is by far my favorite shortcut:

Select a word and press?Cmd+D?to select the next same word. Then press?Cmd+D?again to select the next same word again, and so on.

Press?Cmd+Left Button?to create a cursor for editing everywhere you click.

Block select?Option+Left Button?is used to select a block of text. It’s perfect for removing blank space when formatting a CSV file.

Note:?For more shortcuts, take a look at?this article.

Custom Commands

It’s easy to write your own custom commands and key bindings with Python. I currently use this workflow:

Copy the path of the current file to the clipboard (link).

Close all tabs except the active one (link).

Install these by adding the Python files to your?/Sublime Text 3/Packages/User?directory via the file menu (Sublime > Preferences > Browse Packages) and then opening the User directory. To complete the setup, bind them from the?Key Bindings - User?file (Sublime Text > Preferences > Package Settings > AdvancedNewFile > Key Bindings - User).

[

? // Copy file name

? {

? ? "keys": ["cmd+shift+c"],

? ? "command": "copy_path_to_clipboard"

? },

? // Close all other tabs

? {

? ? "keys": ["cmd+alt+w"],

? ? "command": "close_tabs"

? }

]

Additional Resources

Community-maintained documentation

Package Manager documentation

Unofficial documentation reference

Pimp my Editor - Presentation

Free Bonus:?5 Sublime Text Tweaks to Boost Your Python Productivity, a free email class that shows you how to optimize your Python + Sublime development setup for maximum efficiency.

Conclusion

I hope that 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 questions 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 the resources that I created. Cheers!



<Problems>


我沒(méi)有使用上面的Anaconda插件,而是采用Package Control中的conda插件+conda配置文件的形式怒坯。


一、使用conda插件激活虛擬環(huán)境

conda插件安裝好后,就可以很方便的使用虛擬環(huán)境了逗爹。

1. command + shift + p 輸入conda回車

2. 搜索結(jié)果是conda可以使用的指令谷市,效果似乎比在terminal中更方便


3. 選擇激活環(huán)境后可以彈出環(huán)境列表蛔垢,選擇需要的環(huán)境


4. 記得在Sublime text3- tools -build system中選擇Conda


二、修改conda配置文件

到Preferences->package settings->conda->settings-user中修改相應(yīng)路徑

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末迫悠,一起剝皮案震驚了整個(gè)濱河市鹏漆,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌创泄,老刑警劉巖艺玲,帶你破解...
    沈念sama閱讀 217,734評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異鞠抑,居然都是意外死亡饭聚,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門搁拙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)若治,“玉大人,你說(shuō)我怎么就攤上這事感混《擞祝” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 164,133評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵弧满,是天一觀的道長(zhǎng)婆跑。 經(jīng)常有香客問(wèn)我,道長(zhǎng)庭呜,這世上最難降的妖魔是什么滑进? 我笑而不...
    開(kāi)封第一講書人閱讀 58,532評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮募谎,結(jié)果婚禮上扶关,老公的妹妹穿的比我還像新娘。我一直安慰自己数冬,他們只是感情好节槐,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布搀庶。 她就那樣靜靜地躺著,像睡著了一般铜异。 火紅的嫁衣襯著肌膚如雪哥倔。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 51,462評(píng)論 1 302
  • 那天揍庄,我揣著相機(jī)與錄音咆蒿,去河邊找鬼。 笑死蚂子,一個(gè)胖子當(dāng)著我的面吹牛沃测,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播食茎,決...
    沈念sama閱讀 40,262評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼蒂破,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了董瞻?” 一聲冷哼從身側(cè)響起寞蚌,我...
    開(kāi)封第一講書人閱讀 39,153評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎钠糊,沒(méi)想到半個(gè)月后挟秤,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,587評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡抄伍,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評(píng)論 3 336
  • 正文 我和宋清朗相戀三年艘刚,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片截珍。...
    茶點(diǎn)故事閱讀 39,919評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡攀甚,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出岗喉,到底是詐尸還是另有隱情秋度,我是刑警寧澤,帶...
    沈念sama閱讀 35,635評(píng)論 5 345
  • 正文 年R本政府宣布钱床,位于F島的核電站荚斯,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏查牌。R本人自食惡果不足惜事期,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評(píng)論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望纸颜。 院中可真熱鬧兽泣,春花似錦、人聲如沸胁孙。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,855評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至牵敷,卻和暖如春胡岔,著一層夾襖步出監(jiān)牢的瞬間法希,已是汗流浹背枷餐。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,983評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留苫亦,地道東北人毛肋。 一個(gè)月前我還...
    沈念sama閱讀 48,048評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像屋剑,于是被迫代替她去往敵國(guó)和親润匙。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,331評(píng)論 0 10
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,471評(píng)論 5 6
  • 今日目標(biāo): 1. 臨床技能大賽 2. 處理數(shù)據(jù) 完成情況: 今日反思: 1. 早起:今天在陳琳的帶動(dòng)下起了床唉匾,感謝...
    Xujinqun閱讀 76評(píng)論 0 0
  • 有理數(shù)運(yùn)算是七年級(jí)的教學(xué)內(nèi)容孕讳,在進(jìn)行有理數(shù)的混合運(yùn)算時(shí),為了提高運(yùn)算速度和準(zhǔn)確性巍膘,要靈活運(yùn)用運(yùn)算律厂财,還要能創(chuàng)造條件...
    戰(zhàn)神中的戰(zhàn)神閱讀 5,803評(píng)論 1 0
  • 顏色插值 利用插值使顏色像比例尺一樣過(guò)渡//codevar a = d3.rgb("red");var b ...
    Vijay_閱讀 203評(píng)論 0 0