SublimeText配置

在我的一台开发机上在ubuntu系统下使用eclipse,经常会出现死机,不得不寻求其它的代码编辑器。windows下大名鼎鼎的source insight放到linux下就状况不断。后看到chromium项目推荐了sublime text这款编辑器,用起来感觉还不错。下面记录一下使用过程中的一些设置,网上各种资料比较凌乱,所以就稍微整理一下,供自己今后翻阅。

1. 过滤不相关的文件

可以针对某个特定的工程,进入菜单project | Edit Project,编辑当前工程的sublime-project文件,加入两个过滤器,folder_exclude_patternsfile_exclude_patterns,如下所示:

"folders":
[
    {
        "path":"/home/alex/android/source/android4.2",
        "file_exclude_patterns":
        [
            "*.o"
        ],
        "folder_exclude_pattern":
        [
            ".repo"
        ]
    }
]

2. 模拟eclipse的快捷键

在eclipse中,有几个快捷键用的非常多,分别为:

CTRL+TAB 头文件和c/c++文件之间切换
CTRL+SHIFT+R 对话框中输入文件名(有联想功能),快速打开文件
CTRL+o 输入方法(函数)名,可快速定位到方法(函数)
CTRL+l 输入行号,快速定位到指定行
CTRL+h 打开文件搜索对话框

可以修改sublime text的Key Bindings达到模拟eclipse快捷键的效果,有两个配置项可以修改,一个是Key Bindings-Default,一个是Key Bindings-User,最好修改后一个配置文件。进入菜单Preferences | Key Bindings - User,加入如下行:

[
{ "keys": ["ctrl+shift+r"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
{ "keys": ["ctrl+o"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
{ "keys": ["ctrl+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
{ "keys": ["ctrl+t"], "command": "show_overlay", "args": {"overlay": "goto", "text": "#"} },
{ "keys": ["ctrl+tab"], "command": "switch_file", "args": {"extensions": ["cpp", "cxx", "cc", "c", "hpp", "hxx", "h", "ipp", "inl", "m", "mm"]} }
]

3. 针对项目的代码风格设置

chromium的项目的代码缩进为两个空格,而其它项目的代码缩进一般为4个空格,所以我就希望针对特定的项目进行代码风格设置,方法是编辑当前工程的sublime-project文件,加入如下行(和folders项平级):

"settings":
{
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"draw_white_space": "all"
}

 

发表评论

电子邮件地址不会被公开。

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>