sublime sftp 打开远程文件夹Soda 这个主题不错。有白色可以选。Ctrl+Shift+p 输入install,接着输入  soda,选择  Theme - Soda ,enter即可;默认的theme为:

时间:2024-03-06 18:51:01

sublime使用

2014-10-16 20:30  youxin  阅读(1415)  评论(0编辑  收藏  举报

显示侧板的文件夹:

View -> Side Bar

 菜单【project】-》add folder to  project.把文件夹显示在左边的sidebar上。

安装插件:

package control

通俗易懂地说,这个是你在完成安装SublimeText后必须安装的东西。你问为什么?因为有了这个特殊的“插件包”,你可以很容易地安装、升级、删除,甚至非常方便地查看您已经安装在SublimeText中的包或插件的列表。它通过菜单和对应的行为使这些过程变得非常容易和有组织。

 

1) 按Ctrl+`调出console, 粘贴以下代码到底部命令行并回车:

import urllib2,os;pf=\'Package Control.sublime-package\';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),\'wb\').write(urllib2.urlopen(\'http://sublime.wbond.net/\'+pf.replace(\' \',\'%20\')).read())
2)重启Sublime Text 2。

如果在Perferences->package settings中看到package control这一项,则安装成功。

 

安装sftp:

按下Ctrl+Shift+P调出命令面板

输入install 调出 Install Package 选项并回车,然后输入ftp,下拉列表中会出现一些相关的插件,选中sftp进行安装就行了,装好后还需配置如下:选菜单栏中的File->SFTP/FTP->Set up Server,然后出现一个配置窗口如下,

 

输入相关的配置信息就可以了。参考:http://www.icultivator.com/p/1257.html

 如何在sidebar列出服务器文件夹,并进行编辑。

 

"sync_down_on_open": true, 默认true,

 

 

一篇文章:

总结: 本文介绍两种方法,推荐第二种方法(samba+windows映射)

先贴出sublime打开远程(Linux)目录所需的配置文件(sublime是通过ssh协议从Linux端下载上传文件,来保持同步的,下边的配置文件一部分就是配置ssh,另一部分配置所要打开的Linux目录)

{
    // The tab key will cycle through the settings when first created
    // Visit http://wbond.net/sublime_packages/sftp/settings for help
    
    // sftp, ftp or ftps
    "type": "sftp",

    "save_before_upload": true,
    "upload_on_save": true,
    "sync_down_on_open": true,
    "sync_skip_deletes": false,
    "sync_same_age": true,
    "confirm_downloads": false,
    "confirm_sync": false,
    "confirm_overwrite_newer": false,
    
    "host": "192.0.0.0",
    "user": "username",
    "password": "123456",
    "port": "22",
    
    "remote_path": "/usr/local/mydir",
    "ignore_regexes": [
        "\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
        "sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/",
        "\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini",
        "\\.png", "\\.jpg"
    ],
    //"file_permissions": "664",
    //"dir_permissions": "775",
    
    "extra_list_connections": 4,

    "connect_timeout": 30,
    //"keepalive": 120,
    //"ftp_passive_mode": true,
    //"ftp_obey_passive_host": false,
    //"ssh_key_file": "~/.ssh/id_rsa",
    //"sftp_flags": ["-F", "/path/to/ssh_config"],
    
    "preserve_modification_times": true,
    //"remote_time_offset_in_hours": 0,
    //"remote_encoding": "utf-8",
    //"remote_locale": "C",
    //"allow_config_upload": false,
}

选中文件夹,选中SFTP/FTP->map to remote,会出现如上sftp-config.json,

remote_path这个路径服务器一定要存在,不然上传时会报错说路径不存在,另外我想把这文件夹A上传到nginx的html下面

路径写/opt/nginx/html/a ,后面要带a,否则是把本地A文件夹下的文件传输到html目录

 

在sftp-config文件中,属性ignore_regexes则是表示排除一些文件,这些排除掉掉文件则不和服务器进行同步。

参考链接:https://wbond.net/sublime_packages/sftp/settings

 

注: 可以把 sftp-config.json 文件中的 "upload_on_save" 设置为‘true’,这样修改完文件将会自动上传到服务器上


注意:如果编码引起错误,可能是文件名字有乱码,删掉这些文件;或者在上边贴出的配置文件中,根据后缀将其忽略掉,不down下来)

 

第一步:先在本地创建一个文件夹,用sublime打开

第二步:右键左侧sidbar中这个文件图标,选择SFTP/FTP: SFTP > Map to Remote…

第三步:在弹出的配置文件(如上)中修改相应的配置,ssh的ip,用户名,密码,想要打开的目录等等

第三步:右键文件图标,SFTP > Download Folder,然后等待同步完成

(如果出错,可能是编码的问题,忽略掉编码不正确的文件,或者修改编码,然后再SFTP > sync remote->local)

原文:http://wbond.net/sublime_packages/sftp/sidebar

注意:如果编码引起错误,可能是文件名字有乱码,删掉这些文件;或者在上边贴出的配置文件中,根据后缀将其忽略掉,不down下来

-------------------新方法线------------------------

2014年5月7日 10:08:03

或者简单一点儿,在Linux机上开启samba服务,在windows中将Linux中那个文件夹映射到windows的一个"驱动器"上,

再用sublime text 打开,省的乱码的纠结了,但是要注意Linux上文件的修改权限

2014年5月23日 17:59:58

还有,使用sublime创建project可以通过往这个project添加文件夹的方式,同时打开多个上一步建立的windows端映射驱动器.

 

 

 由于配置 "upload_on_save": true,修改保存后会自动上传至远程服务器。

 

 

Sublime 创建、保存、切换工程

关闭 sublime 后,下次打开时不会记住侧栏的 folders,通过 project 可以方便的管理。

添加:

Project > Add Folder to Project

可以直接把目录拖到 sublime 中

保存、编辑:

Project > Save Project As

点击保存,将在选定的目录生成两个文件:

project_name.sumlime-project:包含工程定义,该文件会被记录到版本控制里。
project_name.sublim-workspace:包含了用户的工程数据,例如打开的文件和修改等,该文件不会被记录到版本控制里。

在 *.sublime-project 文件中( Project > Edit Project),可以定义工程配置。例如可以定义多个目录路径,或者哪些目录或文件需要排除在外。通过定义 “name”,可以将一些长路径或者名字很长的目录以更简洁的名称显示在 sidebar 中。

{
"folders":
    [
        {
            "path": "wwwroot",
            "folder_exclude_patterns": ["images"]
        },
        {
            "path": "c:\wwwroot\project1\assets",
            "name": "Project 1",
            "file_exclude_patterns": ["*.php"]
        }
    ],
    "settings":
    {
        "tab_size": 8
    }
}

 

在编辑区右键:copy file path

    复制文件路径,方便我们复制路径到浏览器中查看.
在编辑区右键Open Containing Folder…,打开包含此文件的文件夹。
 
列编辑:
 多列编辑:按住ctrl点击鼠标,会出现多个闪烁的光标,这时可同时修改多处。或者按住鼠标中键拖拽 。
 
 
主题插件:

安装Colorsublime插件

3.打开Package Control(CTRL +SHIFT+P)

输入install,然后点击Install Theme

 

ColorSublime:一个Sublime主题的网站,推荐使用Package Control的方式来安装ColorSublime插件,安装完可以使用在控制面板中移动上下箭头就可以预览,回车即可安装

 

 

Goto Anything功能 — 快速查找(ctrl + P)

在当前项目中快速搜索文件

快捷键:CTRL + p

这里面有技巧,比如希望搜索如下路径的文件名并打开:

routes/user/messages.js

只需在窗口输入:rum 或者r/u/m。

Use Goto Anything to open files with only a few keystrokes, and instantly jump to symbols, lines or words.

Triggered with Ctrl+P, it is possible to:

Type part of a file name to open it.
Type @ to jump to symbols, # to search within the file, and : to go to a line number.
These shortcuts can be combined, so tp@rf may take you to a function read_file within a file text_parser.py. Similarly, tp:100 would take you to line 100 of the same file.

 

 

更换主题:

// The theme controls the look of Sublime Text\'s UI (buttons, tabs, scroll bars, etc)
"theme": "Default.sublime-theme",

在setting-user覆盖:

"theme": "Soda Light 3.sublime-theme",

保存后发现我们的背景色还是黑色,这是因为主题改变的是主题颜色,背景色是代码颜色,更改preference->color scheme

配置color scheme

  • 到官网下载对应的配置文件,这里为了方便戳一下这里就可以了
  • 把里面的两个配置文件【一个dark,一个是light】放到Packages/User文件夹(打开prefenrce->setting-user文件夹)下面
  • 在Preferences -> Color Scheme -> User这里设置一下对应的color theme就可以了

 

Sublime Text3基本界面等参数设置?

  Sublime Text3默认界面设置配置文件在Preferences---->Settings-Default。

  我们可以通过在Settings-User配置文件中增加值来覆盖Setting-Default中的设置值,设置值的格式可以参看Setting-Default配置文件中设置,例如下面我设置的字体大小、行高亮显示和侧边栏文件夹图标加粗。设置完成后Ctrl+S保存后,无需重启Sublime Text3即可立即生效。如修改:

{
"highlight_line":true,
"font_size": 30, 
}

 

设置字体:

 "font_face": "Courier New"

 

BracketHighlighter 高亮显示匹配的括号、引号和标签

BracketHighlighter这个插件能在左侧高亮显示匹配的括号、引号和标签,能匹配的 [] ,  () ,  {} ,  "" \'\' ,  <tag></tag>等甚至是自定义的标签,当看到密密麻麻的代码分不清标签之间包容嵌套的关系时,这款插件就能很好地帮你理清楚代码结构,快速定位括号,引号和标签内的范围。

BracketHighlighter能为ST提供括号,引号这类高亮功能,但安装此插件后,默认没有高亮,只有下划线表示,不是很醒目,需要如下配置
1. 在ST中用package control安装BracketHighlighter(此是废话)
2. 安装完成后,打开Preferences -> package settings -> Bracket Highlighter -> Bracket Settings – User (注意是user),然后添加如下代码

{
    "bracket_styles": {
        "default": {
            "icon": "dot",
            // "color": "entity.name.class",
            "color": "brackethighlighter.default",
            "style": "highlight"
        },

        "unmatched": {
            "icon": "question",
            "color": "brackethighlighter.unmatched",
            "style": "highlight"
        },
        "curly": {
            "icon": "curly_bracket",
            "color": "brackethighlighter.curly",
            "style": "highlight"
        },
        "round": {
            "icon": "round_bracket",
            "color": "brackethighlighter.round",
            "style": "highlight"
        },
        "square": {
            "icon": "square_bracket",
            "color": "brackethighlighter.square",
            "style": "highlight"
        },
        "angle": {
            "icon": "angle_bracket",
            "color": "brackethighlighter.angle",
            "style": "highlight"
        },
        "tag": {
            "icon": "tag",
            "color": "brackethighlighter.tag",
            "style": "highlight"
        },
        "single_quote": {
            "icon": "single_quote",
            "color": "brackethighlighter.quote",
            "style": "highlight"
        },
        "double_quote": {
            "icon": "double_quote",
            "color": "brackethighlighter.quote",
            "style": "highlight"
        },
        "regex": {
            "icon": "regex",
            "color": "brackethighlighter.quote",
            "style": "outline"
        }
    }

}
View Code

3. 在ST的安装目录中打开packages/user/你的主题.tmTheme,在项里添加如下代码

<!-- Bracket 开始 -->
<dict>
    <key>name</key>
    <string>Bracket Default</string>
    <key>scope</key>
    <string>brackethighlighter.default</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FFFFFF</string>
        <key>background</key>
        <string>#A6E22E</string>
    </dict>
</dict>

<dict>
    <key>name</key>
    <string>Bracket Unmatched</string>
    <key>scope</key>
    <string>brackethighlighter.unmatched</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FFFFFF</string>
        <key>background</key>
        <string>#FF0000</string>
    </dict>
</dict>

<dict>
    <key>name</key>
    <string>Bracket Curly</string>
    <key>scope</key>
    <string>brackethighlighter.curly</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FF00FF</string>
    </dict>
</dict>

<dict>
    <key>name</key>
    <string>Bracket Round</string>
    <key>scope</key>
    <string>brackethighlighter.round</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#E7FF04</string>
    </dict>
</dict>

<dict>
    <key>name</key>
    <string>Bracket Square</string>
    <key>scope</key>
    <string>brackethighlighter.square</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FE4800</string>
    </dict>
</dict>

<dict>
    <key>name</key>
    <string>Bracket Angle</string>
    <key>scope</key>
    <string>brackethighlighter.angle</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#02F78E</string>
    </dict>
</dict>

<dict>
    <key>name</key>
    <string>Bracket Tag</string>
    <key>scope</key>
    <string>brackethighlighter.tag</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FFFFFF</string>
        <key>background</key>
        <string>#0080FF</string>
    </dict>
</dict>

<dict>
    <key>name</key>
    <string>Bracket Quote</string>
    <key>scope</key>
    <string>brackethighlighter.quote</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#56FF00</string>
    </dict>
</dict>
<!-- Bracket 结束 -->
View Code

 

 

为某个格式文件设置高亮

比如你有一大堆txt文件,但是这些txt文件内容是python代码,想要打开txt就用python语法高亮,怎么做,参考下面的:

Sublime Text对于一些常见的扩展名的文件都能够识别并选择Sublime Text内置对应的高亮语法,但是对于一些使用频率比较少的扩展名文件就无法识别,Sublime Text打开此类文件后默认显示成普通文本,没有语法高亮。

虽然我们可以在打开文件后点击右下角的Plain Text,在出现的文件格式中选择自己要显示的语法类型。

但是这样每次打开都需要手动进行一番设置,我们需要一种一劳永逸的方法对此类文件类型进行自动选择语法高亮。

Sublime Text 2版本添加扩展名文件语法是在Data\Packages目录下的文件类型目录里的文件类型语言文件,如XML\XML.tmlanguage。然后打开该文件,在<key>fileTypes</key>下面按照原来的例子添加新的文件类型保存即可。

而Sublime Text 3的目录结构和2的不太一样,使用2的方法就不行了。那么有2中方法可以实现,下面的其一方法在2中也可以使用,不同是的下面的其二方法。

其一:打开文件后点击右下角的Plain Text,在出现的文件格式中选择open all with current extension as…  ->"需要显示的语法类型"。这样以后打开这个类型的文件就会自动进行语法高亮了。

其二:在Data\Packages\User目录下手动生成一个名字叫XXX.sublime-settings的文件。XXX为文件扩展名。

在文件内输入:

{

"extensions":

[

"html",

"dwt",

"lbi"

]

}

添加其他文件类型以此类推...

 

增加vim支持,在自己的配置文件里面,去掉

ignored_packages": ["vintage"]  这个就行了。vintage是vim的包。

 

 sublime ctrl+d 选择单词,重复可增加选择下一个相同的单词.

 

 

sublime不支持除utf8以外的文字乱码解决

装插件:ConvertToUTF8,其实也不是真的支持其他编码,更准确的应该说是把除UTF8编码之外的其他编码在Sublime Text中转换称UTF8编码,但是在保存的时候还是原来的那个编码,从在打开该文件的时候一开始显示的乱码,然后一刹那又自动显示出正常的字体可以看出,当然,在保存文件之后发现其编码还是原来的那个的。
那么应该如何安装ConvertToUTF8呢?
1、通过ctrl+shift+p快捷键组合打开命令面板输入”install package”后回车(在此步骤之前请先确认已经安装好package control)
2、在安装面板上输入”ConvertToUTF8″后回车
3、安静等待安装,此时会出现介绍页面,同时可实时查看左下角状态栏信息了解安装情况,建议安装后重启一下Sublime Text

参考:http://www.cnblogs.com/ifantastic/p/3485943.html

http://blog.jobbole.com/23949/

http://blog.csdn.net/yongan1006/article/details/8806883

 http://www.cnblogs.com/figure9/p/sublime-text-complete-guide.html

 

svn插件使用:

Sublime TortoiseSVN 插件为你提供了在sublime中直接对文件以及文件夹进行svn操作的功能。
它的实现依赖于TortoiseSVN命令行工具TortoiseProc.exe,因此为了保证插件的顺利运行,您的电脑必须已安装TortoiseProc.exe

如果没有请重新安装TortoiseSVN。(TortoiseSVN 安装过程中会有是否安装命令行工具的选项,默认是不勾选的,重新安装时请手工勾选).


TortoiseSVN
-----------

Sublime-TortoiseSVN
=============
sublime-TortoiseSVN is a tiny and simple plugin for [Sublime Text](http://www.sublimetext.com) .
It\'s behavior is similar to [subclipse](http://subclipse.tigris.org/) in [Eclipse](http://www.eclipse.org/).
**It runs only on Windows and needs the TortoiseSVN and TortoiseSVN command line tools (TortoiseProc.exe).**

Usage
============
Install it using [Sublime Package Control](http://wbond.net/sublime_packages/package_control).
If TortoiseSVN is not installed at `C:\\Program Files\\TortoiseSVN\\bin\\TortoiseProc.exe`, specify the correct path
by setting property "tortoiseproc_path" in your TortoiseSVN.sublime-settings file.


The default key bindings are
- [alt+c] : commit current file.
- [alt+u] : update current file.
- [alt+r] : revert current file.

You can also call TortoiseSVN commands when right-clicking folders or files in the side bar.

 SideBarEnhancements

 

sidebar扩展插件。

SideBarEnhancements本是增强侧边栏的插件,这里将教大家如何用来做sublime text 3浏览器预览插件,并可自定义浏览器预览的快捷键。

安装此插件,点击工具栏的preferences > package setting > side bar > Key Building-User,键入以下代码,这里设置按Ctrl+Shift+C复制文件路径,按F1~F5分别在firefox,chrome,IE,safari,opera浏览器预览效果,当然你也可以自己定义喜欢的快捷键,最后注意代码中的浏览器路径要以自己电脑里的文件路径为准。

[
       /*{ "keys": ["alt+f12"],
            "command": "side_bar_open_in_browser",
            "args":{"paths":[], "type":"production", "browser":""}
        },*/
          { "keys": ["ctrl+shift+c"], "command": "copy_path" },
          //chrome
    { "keys": ["f1"], "command": "side_bar_files_open_with",
            "args": {
                "paths": [],
                "application": "C://Program Files (x86)//Google//Chrome//Application//chrome.exe",
                "extensions":".*"
            }
     },
    //firefox
    { "keys": ["f2"], "command": "side_bar_files_open_with",
             "args": {
                "paths": [],
                "application": "E://软件//Firefox//firefox.exe",
                "extensions":".*" //匹配任何文件类型
            }
    },
    //ie
     { "keys": ["f3"], "command": "side_bar_files_open_with",
             "args": {
                "paths": [],
                "application": "C://Program Files//Internet Explorer//iexplore.exe",
                "extensions":".*"
            }
    },
    ]

 

Centos 安装Sublime text 3

 

注意:安装目录因人而异,我的安装目录是/opt/sublime_text_3.

一、建立软件安装目录(我一般把软件安装在opt目录下)

# mkdir /opt
# cd /opt

二、下载软件

http://www.sublimetext.com/3
注意一定要下Ubuntu/tarball包。
也可以用命令下载

wget http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3083_x64.tar.bz2

如果链接地址失效,请到官网获取最新下载地址。

三、解压软件包

tar jxvf sublime_text_3_build_3059_x64.tar.bz2

四、命令行下直接运行

# cd /opt/sublime_text_3
# ./sublime_text

五、创建桌面快捷方式

复制文件

# cp /opt/sublime_text_3/sublime_text.desktop /usr/share/applications

更改配置文件

 
# vim /usr/share/applications/sublime_text.desktop

我的配置如下
[Desktop Entry]
Version=1.0
Type=Application
Name=Sublime Text
GenericName=Text Editor
Comment=Sophisticated text editor for code, markup and prose
Exec=/opt/sublime_text_3/sublime_text %F
Terminal=false
MimeType=text/plain;
Icon=/opt/sublime_text_3/Icon/48x48/sublime-text.png
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;

[Desktop Action Window]
Name=New Window
Exec=/opt/sublime_text_3/sublime_text -n
OnlyShowIn=Unity;

[Desktop Action Document]
Name=New File
Exec=/opt/sublime_text/sublime_text_3 --command new_file
OnlyShowIn=Unity;

六、打开软件

应用程序 >编程 > Sublime Text”右键”将此启动器添加到桌面”

注意:配置文件标注红色的地方对应的是软件安装目录,需要改成你自己的安装目录。

 

设置theme和color scheme

package control上安装soda主题

  • 打开sublime的package install
  • 查找 soda 选择 theme-soda
  • 选择后执行安装

 

  • 打开Settings - User配置文件
  • 末尾追加 "theme": "Soda Light 3.sublime-theme"【注意之前别漏了分号】
  • 保存之后就立马生效了

保存之后发现怎么代码区域还是黑色的背景,菜单栏颜色已经切换了,别急,这里还少了一步,就是配置一下color scheme

配置color scheme

  • 到官网下载对应的配置文件,这里为了方便戳一下这里就可以了
  • 把里面的两个配置文件【一个dark,一个是light】放到Packages/User文件夹下面
  • 在Preferences -> Color Scheme -> User这里设置一下对应的color theme就可以了

yntax highlighting colour schemes

The Soda Light screenshot uses a modified version of Espresso Tutti Colori and the Soda Dark screenshot uses a modified version of Monokai.

If you\'d like to use the syntax highlighting schemes shown in the screenshots:

  • Download colour-schemes.zip
  • Unzip and place the extracted tmtheme files in the Sublime Text Packages/User folder
  • Enable the colour scheme via Preferences -> Color Scheme -> User

 

sublime构建系统 build system

 

${folder}是最上层的目标的绝对路径,也就是game1目标 

 

 

 

http://sublime-text.readthedocs.io/en/latest/reference/build_systems.html

 

Build Systems
Build systems let you run your files through external programs and see the output they generate within Sublime Text.

构建系统可以让您通过外部程序来运行文件,并可以在Sublime Text查看输出。

Build systems consist of two –or optionally three– parts:

configuration data in JSON format (the .sublime-build file contents)
a Sublime Text command driving the build process
optionally, an external executable file (script, binary file)
构建系统包括两 – 或者说三个 – 部分

使用JSON格式保存配置文件 (.sublime-build 内容)
使用Sublime Text命令来驱动构建过程
还包括一个外部的可执行程序(脚本或者二进制)
Essentially, .sublime-build files are configuration data for an external program as well as for the Sublime Text command just mentioned. In them, you specify the switches, options and environment information you want forwarded.

从根本上来讲,.sublime-build 配置文件对于外部可执行程序与前面提到的Sublime Text命令是一样的。在配置文件中可以指定开关、配置以及环境变量。

The Sublime Text command then receives the data stored in the .sublime-build file. At this point, it can do whatever it needs to build the files. By default, build systems will use the exec command, implemented in Packages/Default/exec.py. As we’ll explain below, you can override this command.

Sublime Text命令从 .sublime-build 中读取配置数据,然后根据需要*构建*这些文件。 构建系统缺省会使用``exec`` 命令,该命令在 Packages/Default/exec.py 中实现。 在后续的讲解中,我们会重写这个命令。

Lastly, the external program may be a shell script you’ve created to process your files, or a well-known utility like make or tidy. Usually, these executable files will receive paths to files or directories, along with switches and options to be run with.

外部程序可能是你用来处理文件的脚本,也可以能是类似 make 或 tidy 这类的命令。通常,这些可执行文件从配置中获取文件路径或者目录以及运行是需要的开关及选项。

Note that build systems need not call any external program at all if there isn’t any reason to; you could implement a build system entirely in a Sublime Text command.

注意,构建系统可以完全不依赖调用外部程序,完全可以通过Sublime Text

文件格式
.构建系统 文件使用JSON. 以下是一个例子:

{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
选项
cmd
Array containing the command to run and its desired arguments. If you don’t specify an absolute path, the external program will be searched in your PATH, one of your system’s environmental variables.
cmd

包括命令及其参数数组。如果不指定绝对路径,外部程序会在你系统的:const:PATH 环境变量中搜索。

On Windows, GUIs are supressed.

在Windows 系统中,*TBT*

file_regex
Optional. Regular expression (Perl-style) to capture error output of cmd. See the next section for details.
file_regex
可选。 Perl格式的正则表达式可以获取``cmd``的错误输出,详情参考下一节
line_regex
Optional. If file_regex doesn’t match on the current line, but line_regex exists, and it does match on the current line, then walk backwards through the buffer until a line matching file regex is found, and use these two matches to determine the file and line to go to.
line_regex

可选。当``file_regex``与该行不匹配,如果``line_regex``存在,并且确实与当前行匹配, 则遍历整个缓冲区,直到与``file regex``匹配的行出现,并用这两个匹配决定最终要跳转的文件 或行。
selector
Optional. Used when Tools | Build System | Automatic is set to true. Sublime Text uses this scope selector to find the appropriate build system for the active view.
selector
可选。在选定 Tools | Build System | Automatic 时使用。Sublime Text使用这个 选择器自动为活动试图选择构建系统。
working_dir
Optional. Directory to change the current directory to before running cmd. The original current directory is restored afterwards.
working_dir
可选。在运行``cmd``前会切换到该目录。运行结束后会切换到原来的目录。
encoding
Optional. Output encoding of cmd. Must be a valid python encoding. Defaults to UTF-8.
encoding
可选。输出``cmd``的编码。必须是合法的Python编码,缺省为``UTF-8``。
target
Optional. Sublime Text command to run. Defaults to exec (Packages/Default/exec.py). This command receives the configuration data specified in the .build-system file.

Used to override the default build system command. Note that if you choose to override the default command for build systems, you can add arbitrary variables in the .sublime-build file.

target
可选。运行的Sublime Text命令,缺省为``exec`` (Packages/Default/exec.py)。该命令从 *.build-system*中获取配置数据。

用来替代缺省的构建系统命令。注意,如果你希望替代构建系统的缺省命令,请在*.sublime-build* 文件中专门设置。

env
Optional. Dictionary of environment variables to be merged with the current process’ before passing them to cmd.

Use this element, for example, to add or modify environment variables without modifying your system’s settings.

env
可选。在环境变量被传递给``cmd``前,将他们封装成词典。
shell
Optional. If true, cmd will be run through the shell (cmd.exe, bash…).
shell
可选。如果该选项为``true`` ,``cmd``则可以通过shell运行。
path
Optional. This string will replace the current process’ PATH before calling cmd. The old PATHvalue will be restored after that.

Use this option to add directories to PATH without having to modify your system’s settings.

path
可选。该选项可以在调用``cmd``前替换当前进程的’ PATH 。原来的’ PATH 将在运行后恢复。

使用这个选项可以在不修改系统设置的前提下将目录添加到’ PATH 中。

variants
Optional. A list of dictionaries of options to override the main build system’s options. Variant ``name``s will appear in the Command Palette for easy access if the build system’s selector matches for the active file.
variants
可选。用来替代主构建系统的备选。如果构建系统的选择器与激活的文件匹配,变量的``名称``则 会出现在 Command Palette 中。
name
Only valid inside a variant (see variants). Identifies variant build systems. If name is Run, the variant will show up under the Tools | Build System menu and be bound to Ctrl + Shift + B.
name
仅在variant中是合法的 (详见 variants)。用来标识系统中不同的构建系统。如果 ``name``是*Run* ,则会显示在**Tools | Build System** 下,并且可以使用 *Ctrl + Shift + B*调用。
使用 ``file_regex``获取错误输出
The file_regex option uses a Perl-style regular expression to capture up to four fields of error information from the build program’s output, namely: file name, line number, column number and error message. Use groups in the pattern to capture this information. The file name field and the line number field are required.

``file_regex``选项用Perl的正则表达式来捕获构建系统的错误输出,主要包括四部分内容,分别是 file name*, line number, column number and error message. Sublime Text 在匹配模式中使用分组的方式捕获信息。file name 和 *line number*域是必须的。

When error information is captured, you can navigate to error instances in your project’s files with F4 and Shift+F4. If available, the captured error message will be displayed in the status bar.

当错误信息被捕获时,你可以使用``F4`` 和 ``Shift+F4``在你的项目文件中跳转。被捕获的*错误 信息*会显示在状态栏。

平台相关选项
The windows, osx and linux elements let you provide platform-specific data in the build system. Here’s an example:

``windows``, ``osx`` 以及 ``linux``元素可以帮助你在构建系统中设定平台相关
的选项,举例如下:

{
“cmd”: [“ant”], “file_regex”: “^ 
javac
javac
(.+):([0-9]+):() (.)$”, “working_dir”: “${project_path:${folder}}”, “selector”: “source.java”,

“windows”: {

“cmd”: [“ant.bat”]
}

}

In this case, ant will be executed for every platform except Windows, where ant.bat will be used instead.

在这个例子中,ant``在除了Windows之外的平台中都是执行 ant ,而在Windows中则执行 ``ant.bat

构建系统备选项
如下是一个带有备选项的构建系统实例:

{
"selector": "source.python",
"cmd": ["date"],

"variants": [

{ "cmd": ["ls -l *.py"],
"name": "List Python Files",
"shell": true
},

{ "cmd": ["wc", "$file"],
"name": "Word Count (current file)"
},

{ "cmd": ["python", "-u", "$file"],
"name": "Run"
}
]
}
Given these settings, Ctrl + B would run the date command, Crtl + Shift + B would run the Python interpreter and the remaining variants would appear in the Command Palette whenever the build system was active.

根据以上的设定,按 Ctrl + B 会运行*date*命令, 按 Crtl + Shift + B 会运行Python 解释器,并且在构建系统激活时将剩余的备选项显示在Command Palette中。

构建系统变量
Build systems expand the following variables in .sublime-build files:

在*.sublime-build* 中包括如下构建系统变量。

$file_path 当前文件所在路径, 比如 C:\Files.
$file 当前文件的完整路径, 比如 C:\Files\Chapter1.txt.
$file_name 当前文件的文件名, 比如 Chapter1.txt.
$file_extension 当前文件的扩展名, 比如 txt.
$file_base_name 当前文件仅包含文件名的部分, 比如 Document.
$packages Packages 文件夹的完整路径.
$project 当前项目文件的完整路径.
$project_path 当前项目文件的路径.
$project_name 当前项目文件的名称.
$project_extension 当前项目文件的扩展部分.
$project_base_name 当前项目仅包括名的部分.
变量用法
Features found in snippets can be used with these variables. For example:

可以在代码片段上中使用以上变量。例如:

${project_name:Default}
This will emit the name of the current project if there is one, otherwise Default.

如果当前项目存在则使用该项目名称,否则则使用``Default``替代

${file/\.php/\.txt/}
This will emit the full path of the current file, replacing .php with .txt.

该例会获取当前文件的完整路径,并用*.txt*替换路径中的*.php*

运行构建系统
Select the desired build system from Tools | Build System, and then select Tools | Build or press F7.

从**Tools | Build System**选择构建系统,然后选择**Tools | Build** ,再按``F7``。

构建系统常见问题
Build systems will look for executables in your PATH, unless you specify an absolute path to the executable. Therefore, your PATH variable must be correctly set.

如果你没有为构建系统指定一个可执行文件的绝对路径,构建系统怎么会在你的 PATH 中进行查找。 所以,你需要正确设置 PATH 。

On some operating systems, the value for PATH will vary from a terminal window to a graphical application. Thus, even if the command you are using in your build system works in the command line, it may not work from Sublime Text. This is due to user profiles in shells.

在某些操作系统中,终端和图形化应用的 PATH 值会有所不同。所以即便你的构建系统在命令行下 可以正常工作,在Sublime Text也不见得能够正常。这与Shell中的用户设置有关。

To solve this issue, make sure you set the desired PATH so that graphical applications such as Sublime Text can find it. See the links below for more information.

为了解决这个问题,请确认你正确设置了 PATH ,以便类似Sublime Text一类的图形化应用 可以正确找到。更多内容,请参考一下链接

Alternatively, you can use the path element in .sublime-build files to override the PATH used to locate the executable specified in cmd. This new value for PATH will only be in effect for as long as your build system is running. After that, the old PATH will be restored.

另外,你也可以在 .sublime-build 文件中设定 path 来替代:const:PATH ,并在 path 指定的路径中查找 cmd 可执行文件。新设定的值,仅在构建系统运行期间有效,过后将会恢复为原始的
---------------------
作者:lyctianya
来源:CSDN
原文:https://blog.csdn.net/lyctianya/article/details/70234029
版权声明:本文为博主原创文章,转载请附上博文链接!