Sublime Text目前非常流行,其功能强大到许多的web开发者爱不释手无法自拔,哈哈。最近自己也由原来的BBEdit转战为Sublime Text,由于自己常常会使用到单文件调试代码片段的执行情况,所以让Sublime Text支持单文件调试php、java文件的需求迫在眉睫。
Tips:本人使用的是Sublime Text 2,version 3没有尝试过,不过在版本更新说明中对于Build System的变更不大,也是可以支持的。
Sublime Text 的构建系统(Build System)可以让我们通过外部程序来运行文件,并可以在Sublime Text 的Console中查看输出,其功能配置在“Tools > Build System”。
构建系统包括三部分:
(1)使用JSON格式保存配置文件(.sublime-build)
(2)使用Sublime Text命令驱动构建过程
(3)可选的,还可以包括一个外部的可执行文件(脚本或二进制文件)
文件格式:
1 | { |
{
"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"
}
]
}
1 |
|
{
"cmd": ["php", "$file"],
"file_regex": "php$",
"selector": "source.php"
}
2、Java
> 快捷键:Command + B(编译) => Command + shift + B(执行)
配置详情:
{
"cmd": ["javac", "-encoding", "UTF-8", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"encoding": "UTF-8",
"variants": [{
"name": "Run",
"cmd": ["java", "$file_base_name"],
"encoding": "UTF-8"
}]
}
参考资料链接:
非官方Build System说明:[http://sublime-text-unofficial-documentation.readthedocs.org/en/sublime-text-2/reference/build_systems.html](http://sublime-text-unofficial-documentation.readthedocs.org/en/sublime-text-2/reference/build_systems.html)