您的位置:首页 > 编程语言 > Python开发

设置 Sublime Text 的 Python 开发环境

2014-01-13 16:56 615 查看


Sublime Text 的 Python 开发环境


字体的选择

Ubuntu Mono 是非常非常不错的字体。前些天我刚从 Menlo 切换过来,这绝对不让人后悔。

在我的15寸的MacBook上,Ubuntu Mono的16号字非常适合。1680 × 1050的分辨率对于一个边栏加两个编辑器窗口(自动调整到80个字符宽)刚好合适。

如果你打算认真的挑选一下字体, slant.co的这篇文章 写的不错。它包含了大部分流行的编程方面的字体的截图及下载链接。


安装插件

正如之前提到的, Sublime 有一个非常丰富的插件系统。而我当前使用的插件如下:

Package Control
Sublime 里直接安装附加插件的包管理器。这是唯一一个你必须手动安装的插件。这边列出的其他所有插件都可以通过 Package Control 来安装。也可以通过它来更新已安装过的插件。简单得想做是 Sublime packages 的 apt-get
就行了。
Color Scheme - Tomorrow Night Color
schemes 决定了编辑器界面语法高亮的字体颜色。这是一个非常酷的暗黑系样式。
Theme
- Soda Dark Themes 影响 Sublime 界面元素的颜色和风格。这个非常适合 Tomorrow Night 的配色方案。
SideBarEnhancements 这个插件提供了侧边栏附加的上下文菜单选项,例如"New
file","New Floder"等。这些本应当默认就该有的,却没有。
All Autocomplete Sublime
默认的自动完成只关注当前文件的单词。这个插件扩展了其自动完成的单词列表到所有打开的文件。
SublimeCodeIntel 为部分语言增强自动完成功能,包括了
Python 。这个插件同时也可以让你跳转到符号定义的地方,通过按住 alt 并点击符号。非常方便。
SublimeREPL 允许你在编辑界面直接运行
Python 解释器。我倾向于在单独的终端窗口用 bpython 来运行,但有时 SublimeREPL 是很有帮助的。
GitGutter 在编辑器的凹槽区,依照
Git ,增加小图标来标识一行是否被插入、修改或删除。在 GitGutter 的 readme 中有说明如何更改颜色图标来更新你的配色方案文件。
Pylinter 这个插件提供了目前我所见到的最好的 pylint 编辑器整合。它自动检查
.py 文件,无论其何时被保存,并且会直接在编辑界面显示 pylint 违规。它还有一个快捷方式来禁用局部的 pylint 检查,通过插入一个 #pylint:禁用注释。这个插件对于我确实非常有用。


配置文件

Sublime Text 的一个优点就是它的所有配置都是简单的基于 JSON 的配置文件。这使得你可以很容易的将配置转到另一个系统中。我也见过一些人使用 Dropbox
自动同步他们所有电脑上的配置。

Preferences.sublime-settings 配置了 Sublimede 的显示和行为.你可以在sublime 中通过 Preferences > Settings — User 打开并编辑此文件。我使用如下配置:

01
{
02
//
Colors
03
"color_scheme"
:
"Packages/Tomorrow
Color Schemes/Tomorrow-Night.tmTheme"
,
04
"theme"
:
"Soda
Dark.sublime-theme"
,
05
06
//
Font
07
"font_face"
:
"Ubuntu
Mono"
,
08
"font_size"
:
16.0,
09
"font_options"
:
[
"subpixel_antialias"
,
"no_bold"
],
10
"line_padding_bottom"
:
0,
11
"line_padding_top"
:
0,
12
13
//
Cursor style - no blinking and slightly wider than default
14
"caret_style"
:
"solid"
,
15
"wide_caret"
:
true
,
16
17
//
Editor view look-and-feel
18
"draw_white_space"
:
"all"
,
19
"fold_buttons"
:
false
,
20
"highlight_line"
:
true
,
21
"auto_complete"
:
false
,
22
"show_minimap"
:
false
,
23
24
//
Editor behavior
25
"scroll_past_end"
:
false
,
26
"highlight_modified_tabs"
:
true
,
27
"find_selected_text"
:
true
,
28
29
//
Word wrapping - follow PEP 8 recommendations
30
"rulers"
:
[ 72,79 ],
31
"word_wrap"
:
true
,
32
"wrap_width"
:
80,
33
34
//
Whitespace - no tabs,trimming,end files with \n
35
"tab_size"
:
4,
36
"translate_tabs_to_spaces"
:
true
,
37
"trim_trailing_white_space_on_save"
:
true
,
38
"ensure_newline_at_eof_on_save"
:
true
,
39
40
//
Sidebar - exclude distracting files and folders
41
"file_exclude_patterns"
:
42
[
43
".DS_Store"
,
44
"*.pid"
,
45
"*.pyc"
46
],
47
"folder_exclude_patterns"
:
48
[
49
".git"
,
50
"__pycache__"
,
51
"env"
,
52
"env3"
53
]
54
}
Pylinter.sublime-settings配置了pylinter 插件。我使用下面的配置让 Pyhton 在保存时自动规范,并对违反规范显示图标。

view
source

print?

01
{
02
//
Configure pylint's behavior
03
"pylint_rc"
:
"/Users/daniel/dev/pylintrc"
,
04
05
//
Show different icons for errors,warnings,etc.
06
"use_icons"
:
true
,
07
08
//
Automatically run Pylinter when saving a Python document
09
"run_on_save"
:
true
,
10
11
//
Don't hide pylint messages when moving the cursor
12
"message_stay"
:
true
13
}


按键绑定

Sublime 的按键绑定也是全部可配置的基于JSON的 sublime-keymap 配置文件。我修改了一些默认配置以更好的配合我的 TextMate / IntelliJ 肌肉记忆。你可以完全不修改。如果你想,修改很简单,并可以跨平台使用。我使用如下的绑定:

view
source

print?

01
[
02
//
Rebind "go to file" to cmd+shift+O
03
{
"keys"
:
[
"super+shift+o"
],
"command"
:
"show_overlay"
,
"args"
:
{
04
"overlay"
:
"goto"
,
05
"show_files"
:
true
06
}},
07
08
//
Rebind swap line up/down to cmd+shift+up/down
09
{
"keys"
:
[
"super+shift+up"
],
"command"
:
"swap_line_up"
},
10
{
"keys"
:
[
"super+shift+down"
],
"command"
:
"swap_line_down"
},
11
12
//
Delete a line with cmd+delete
13
{
"keys"
:
[
"super+backspace"
],
"command"
:
"run_macro_file"
,
"args"
:
{
14
"file"
:
"Packages/Default/Delete
Line.sublime-macro"
15
}},
16
17
//
Reindent selection with cmd+alt+L
18
{
"keys"
:
[
"super+alt+l"
],
"command"
:
"reindent"
}
19
]


命令行工具

同 TextMate 的 mate 类似,Sublime Text 包含了一个命令行工具,允许你通过 shell 打开编辑器。工具名为 sublis,默认不可用。要使之生效,在任一 shell 中运行下面:

1
ln
-s
/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/
local
/bin/subl
要将 Sublime 作为 git 互动命令的默认编辑器使用——举例,撰写提交信息——只需添加下面一行到你的 ~/.profile 文件:

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


更多灵感

我希望这篇安装指南能够帮到你。如果你有任何建议或意见,敬请 Twitter 我一行或给我发邮件。另外,感谢下面的作者及其关于配置 sublime 的作品。它们启发了我很多:

Kenneth Reitz:Sublime Text 2 Love
Drew Barontini:Sublime (2)
Filippo Pacifici:Python
development with Sublime Text 2 tips and tricks
opensourcehacker.org:Sublime
Text 2 tips for Python and web developers

转发自 http://www.oschina.net/translate/setting-up-sublime-text-for-python-development
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: