See Alse PythonVim

Sublime Text 2

Sublime Text 是一个及其强大但小巧的文本编辑器,用来编写代码、标记性语言;支持Mac/Linux/Windows平台。

1. 为什么我们都用ST2

Sublime Text 2的评估版可以无限使用,尽管每天会弹出一次提示框让你购买License。


为了简洁的目的,后面吧Sublime Text 2 简称为ST2或者ST。

2. 基本概念


2.1. Packages & Plugins

Install Package Control First!

Press Ctr+`, enter below code and press enter, restart Subline Text

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen(''+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'


2.1.1. The Packages Directory

from the Sublime Text menu: Preferences -> Browse Packages

api call: sublime.packages_path()

2.1.2. Package Management

Cmd+Shift+P(Tools -> Command Palette), Press install and select "Package Control: Install Package" and press enter

Same as Remove Pakcage

List Installed Packages:

        Preferences -> Package Settings

Cmd+Shift+P, search for "Package Control: Remove Package" to remove installed packages

2.1.3. File Navigator(open file by cmd)

cmd++shift+o on OSX or ctrl+shift+o on Windows

cmd+o then cmd+shift+g

2.1.4. SublimeGDB(c debugger)

Install: Cmd+Shift+P, select "Package Control: Install Package" and pree ss enter, type "SublimeGDB", select and install

3. 文本编辑

3.1. 多行选择

Refer 列选择

3.2. 多选

Refer 键盘多选

4. 查找与替换

5. Building System

编译功能可以按F7键或从菜单 Tools -> Build

5.1. Compile and Run for C programming language

Tools -> Build System -> New Build System

"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}", "-lm", "-Wall"],
"selector" : "source.c",
"working_dir" : "$file_path", 
                "name": "Run",
                "cmd": "${file_path}/${file_base_name}" 


6. 订制我的ST2

6.1. 配置文件


    Packages/Default/Preferences (<platform>).sublime-settings
    <Project Settings>
    <Buffer Specific Settings> 

6.2. 字体设置

Add in Packages/User/Preferences.sublime-settings click Preferences → Settings - User / CMD+,

        //...other configurations
        "font_face": "Monaco",
        "font_size": 16.0,

        "add_before_me": true

6.3. 代码缩进(Indentation)

我的习惯是tab, size=4 space, reference here.

Add in Packages/User/Preferences.sublime-settings click Preferences → Settings - User / CMD+,

        //...other configurations
        "tab_size": 4,
        "translate_tabs_to_spaces": false,

        "add_before_me": true

6.4. 注入代码段(snippets)

reference here.

6.4.1. Config Storage

Snippets can be stored under any package’s folder, but to keep it simple while you’re learning, you can save them to your Packages/User folder.

为了确保代码段配置能保存在Packages/User目录,首先呼出用户配置: CMD+,(Preference | Setting - User),然后选择 Tools | New Snippet

6.4.2. C Head Sample

 *  author: liyan(
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <!-- <tabTrigger>hello</tabTrigger> -->
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        <!-- <scope>source.python</scope> -->
        <description>C Head Snippet</description>

Save as head.sublime-snippet

Usage: type head+TAB

6.5. Key Bindings

reference here.

        Preferences → Key Bindings → User

6.5.1. (super+shift+r)Reindent Text in Sublime

        //other keys settings seperate by comma,
        {"keys": ["super+shift+r"], "command": "reindent" , "args": {"single_line": false}}

6.5.2. (super+r)list functions

6.5.3. (super+x)line delete

7. Reference

CategorymacOS CategoryTool CategoryDev