sublime--执行代码
2017-08-08 本文已影响470人
xigua1234
如果是已经支持的语言,直接CTRL+B(CTRL+SHIFT+B)
如果暂不支持,就在顶部菜单
Tools--Build system--New build system
然后,出现语言编译设置文件(以shell为例),默认的内容是:{ "shell_cmd": "make"}.修改为下面的内容,保存为shell.sublime-bulid。
{
"cmd": ["bash","$file"]
}
然后,Tools--Build system中选择刚刚一种语言(shell ).再使用CTRL+B编译执行就行了。
但是,这样不能自动识别语言,每次都要手动选择
改进:
{
"cmd": ["bash","$file"],
"file_regex": "shell$",
"selector": "source.shell"
}
如果你保存的语言编译设置文件为A.sublime-build
就是
{
"cmd": ["bash","$file"],
"file_regex": "A$",
"selector": "source.A"
}
多选项十分必要,如选择编译,执行,还是检查代码
添加一个"variants"参数,添加执行py2、py3,检查py2、py3的选项
{
"cmd": "python3 -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env":
{"PYTHONIOENCODING": "utf-8",
},
"variants":
[
{
"name": "Syntax Check(py2)",
"shell_cmd": "python -m py_compile \"${file}\"",
},
{
"name": "Syntax Check(py3)",
"shell_cmd": "python3 -m py_compile \"${file}\"",
},
{ "name": "Run py2",
"cmd": ["python2", "-u", "$file"]
},
{ "name": "Run py3",
"cmd": ["python3", "-u", "$file"]
},
{ "name": "List Python Files",
"cmd": ["ls -l *.py"],
"shell": true
},
{ "name": "Word Count (current file)",
"cmd": ["wc", "$file"]
},
{
"name":"py2 -> py3",
"cmd" :["python3","-m","lib2to3","-nw","-o","out","$file"]
},
{
"name":"编译exe",
"cmd" :["pyinstaller","--console","--onefile","$file"]
}
]
}
如何修改sublime自带的语言?
python就是软件自带支持的语言,要修改它,要么就新建一个算了。要么修改它内部的Python.sublime-build
Python.sublime-build是直接找不到的,可以通过PackageResourceViewer插件来找到内部文件。
安装插件方法自行百度,安装好后,Ctrl+Shift+P,输入open
找到并进入PackageResourceViewer:Open Resource。
再输入并进入python,找到并进入Python.sublime-build
然后就打开这个软件内部文件了。
推荐教程:
http://sublime-text.readthedocs.io/en/latest/reference/build_systems.html