Sublime Text2 设置C编译环境

1、下载安装MinGW到C:\MinGW,把C:\MinGW\bin加入到Path环境变量里

2、下载解压Sublime Text2, 修改安装目录下的 Data\Packages\Default\exec.py 以支持中文,第45行改为

 

# proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())
proc_env[k] = os.path.expandvars(v.decode(sys.getfilesystemencoding())).encode(sys.getfilesystemencoding())

 

 

 3、设置编译命令,新建空白文件C.sublime-build(大小写,名称固定),将该文件放到安装目录的Data\Packages\User下,粘贴以下内容:

{
    "cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c",

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["cmd", "/c", "gcc", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "cmd", "/c", "${file_path}/${file_base_name}"]
        },
        {
            "name": "RunInCommand",
            "cmd": ["cmd", "/c", "gcc", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & pause"]
        }
    ]
}

4、添加快捷键ctrl+shift+alt+b,可以在cmd里运行:

Perferences->Key Bindings User 里添加

 

{ "keys": ["ctrl+alt+shift+b"], "command": "build", "args": {"variant": "RunInCommand"} },

 

5、编写测试文件,ctrl+b编译,ctrl+shift+b编译运行,ctrl+shift+alt+b,在cmd里运行

 

你可能感兴趣的:(Sublime Text)