设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

设置 Sublime Text 的 Python 开发环境

2013-5-31 11:27| 发布者: 红黑魂| 查看: 8253| 评论: 0|来自: 开源中国

摘要:   最近,当我主要使用Python开发环境编辑的时候,我开始越来越多地用到Sublinme Text 2.这篇文章主要说明了能让Python的编程者使用更方便的一些设置和调整。为何选择Sublime Text?我以前一直是TextMate的忠实用户 ...

配置文件

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 在保存时自动规范,

并对违反规范显示图标。

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 肌肉记忆。你可以完全不修改。如果你想,修改很简单,

并可以跨平台使用。我使用如下的绑定:

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 中运行下面:

1ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl
/usr/
local/bin/subl

要将 Sublime 作为 git 互动命令的默认编辑器使用——举例,撰写提交信息——只需添加

下面一行到你的 ~/.profile 文件:

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

更多灵感

我希望这篇安装指南能够帮到你。如果你有任何建议或意见,敬请 Twitter 我一行或给我发邮件。

另外,感谢下面的作者及其关于配置 sublime 的作品。它们启发了我很多:



参与翻译(4人)


酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部