sublime text 3 build systerm 构建系统(python ,php)

sublime text 3 build systerm 构建系统

参考资料:

快捷键:

  • ctrl + B : 编译
  • F4 : 跳到 后一个编译错误
  • shift + f4 : 跳到前一个编译错误
  • ctrl + break : Tools – > Cancel Build : 取消编译

python 构建系统

我安装python的时候,选择了添加到"系统变量". sublime text 3 本身也内置了 python的构建系统. 如图:

本身我们也可以查看sublime text3 内置的 Python.sublime-build. 在你的安装目录 sublime text3/Package/ 目录下寻找一个Python.sublime-package的压缩文件.
进行解压到Python目录:

打开sublime text3 自带的Python.sublime-build

{
    "shell_cmd": "python -u \"$file\"",
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",

    "env": {"PYTHONIOENCODING": "utf-8"},

    "variants":
    [
        {
            "name": "Syntax Check",
            "shell_cmd": "python -m py_compile \"${file}\"",
        }
    ]
}

因此,实际上并不需要我们自己再次为Python建立一个新的构建系统.


如果我们同时安装了python2 和python3, 我们想要进行切换运行

办法:除了系统自带的Python.sublime-build ,我们自己可以创建Python2.sublime-build, Python3.sublime-build

  • 第一步: tools->build system -> new build systrm

  • 第二步: 在Python3.7.sublime-build中填充代码

{
    "cmd": ["python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}
  • 第三步:实际上.上面的代码已经可以了(因为我的系统变量中只有一个python).但是为了python2和python3的切换,我们可以做一点修改.
{
    "cmd": ["H:\\Program Files\\Python\\Python37\\python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

注意上面是"\\" ,不是"\"; 并且有python.exe

  • 第四步: 上面出现一个问题,输出中文时乱码. 根据默认的Python.sublime-build 添加一个配置项. 终极配置如下:
{
    "cmd": ["H:\\Program Files\\Python\\Python37\\python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "env": {"PYTHONIOENCODING": "utf-8"}
}

这样就可以手动选择不同版本的Python解析器进行解析了.

PHP构建系统

第一种:

{
    "cmd": ["php","$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.php"
}

第二种:

{
    // "cmd": ["php","$file"],
    "cmd": ["H:\\wamp\\php\\php.exe","$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.php"
}

猜你喜欢

转载自blog.csdn.net/cd_za/article/details/86486487