最近,當我主要使用Python開發環境編輯的時候,我開始越來越多地用到Sublinme Text 2.這篇文章主要說明了能讓Python的編程者使用更方便的一些設置和調整。
為何選擇Sublime Text?
我以前一直是TextMate的忠實用戶。這是一個輕量級的、開源的軟件,作為OS X的本地應用,具有很好的Mac風格。不過,雖然TextMate是一個很棒的編輯器,有時候還是顯得功能不夠。
我用過一些功能更強的軟件,例如 加上Python插件的IntelliJ IDEA。 我特別喜歡它的debugger和test runner。不過,一個像IntelliJ這樣的全功能的IDE對於中小項目來說還是顯得過於龐大。
最近幾周我開始越來越多的使用 Sublime Text。當我將它安裝好之後,感覺非常不錯。它確實非常快,自動定期的更新,以及更棒的是完全支持跨平台。對我來說,它最終勝過TextMate的地方是Sublime強大的插件子系統。對於Python開發,有不少插件可以讓你開發起來更流暢、更有樂趣。
我現在仍然在不同的項目之間切換編輯器。不過我發現對應Python開發,Sublime在輕量級的編輯器和全功能的IDE之間有著很好的平衡。
字體的選擇
Ubuntu Mono 是非常非常不錯的字體。前些天我剛從 Menlo 切換過來,這絕對不讓人後悔。
在我的15寸的MacBook上,Ubuntu Mono的16號字非常適合。1680 × 1050的分辨率對於一個邊欄加兩個編輯器窗口(自動調整到80個字符寬)剛好合適。
如果你打算認真的挑選一下字體, slant.co的這篇文章 寫的不錯。它包含了大部分流行的編程方面的字體的截圖及下載鏈接。
安裝插件
正如之前提到的, Sublime 有一個非常豐富的插件系統。而我當前使用的插件如下:
{ // 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_bold"], "line_padding_bottom": 0, "line_padding_top": 0, // Cursor style - no blinking and slightly wider than default "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 behavior "scroll_past_end": false, "highlight_modified_tabs": true, "find_selected_text": true, // Word wrapping - follow PEP 8 recommendations "rulers": [ 72, 79 ], "word_wrap": true, "wrap_width": 80, // 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" ] }
{ // 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 hide pylint messages when moving the cursor "message_stay": true }
[ // Rebind "go to file" to cmd+shift+O { "keys": ["super+shift+o"], "command": "show_overlay", "args": { "overlay": "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": "Packages/Default/Delete Line.sublime-macro" }}, // Reindent selection with cmd+alt+L { "keys": ["super+alt+l"], "command": "reindent"} ]
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
要將 Sublime 作為 git 互動命令的默認編輯器使用——舉例,撰寫提交信息——只需添加下面一行到你的 ~/.profile 文件:
export GIT_EDITOR="subl --wait --new-window"