See Alse Python

Sublime Text 2

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

1. 为什么我们都用ST2

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

目前最新的是3.0,但必须购买License才能长期使用。

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

2. 基本概念

ST在默认安装的情况下就支持40多种语言的语法高亮、格式缩进的基本功能,十分的简单实用。而如果想要用的更加舒适简洁也是可以支持的非常妥帖的,要想用得舒爽,还请继续阅读。

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('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

ST使用了包(Package)的概念,和一些编程语言(例如Java)的含义类似,都是指在一个目录里为完成一个目的而存在的多个文件;显而易见,插件也是用包的形式来组织和存储的。

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)

https://github.com/csch0/SublimeText-File-Navigator

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

cmd+o then cmd+shift+g

2.1.4. SublimeGDB(c debugger)

https://github.com/quarnster/SublimeGDB

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",
"shell":false,
"working_dir" : "$file_path", 
 "variants":[
    {
                "name": "Run",
                "cmd": "${file_path}/${file_base_name}" 
        }
]
}

Tools.Build=Cmd+B/Tools.Run=Shift+Cmd+B

6. 订制我的ST2

6.1. 配置文件

在菜单的Preferences下面,对应如下的文件

    Packages/Default/Preferences.sublime-settings
    Packages/Default/Preferences (<platform>).sublime-settings
    Packages/User/Preferences.sublime-settings
    <Project Settings>
    Packages/<syntax>/<syntax>.sublime-settings
    Packages/User/<syntax>.sublime-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

<snippet>
        <content><![CDATA[
/*==========================================
 *  
 *  $TM_FILENAME: 
 *  author: liyan(twotwo.li@163.com)
 *  
 ==========================================*/
]]></content>
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <!-- <tabTrigger>hello</tabTrigger> -->
        <tabTrigger>head</tabTrigger>
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        <!-- <scope>source.python</scope> -->
        <scope>source.c</scope>
        <description>C Head Snippet</description>
</snippet>

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

https://joshbetz.com/2012/09/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

MainWiki: Sublime_Text (last edited 2014-05-25 20:42:09 by twotwo)