Sublime Text3是个很好用的轻量编辑器,支持多语言语法高亮,自动补全,快捷键编译运行,UI简洁。
但是,这个编辑器的的编译运行功能有点令人难受,它是把shell执行的结果读回来显示在终端,这意味着什么呢?这意味着不支持scanf、input等语法,我们无法使用输入语句,无法使用调试功能。
以下为解决方法
在 sublime -> 工具 -> 编译系统 里新建编译系统,输入以下内容
C语言编译器,支持GDB
{ "cmd" : ["gcc", "$file_name", "-o", "${file_base_name}", "-lm", "-Wall"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "selector" : "source.c, source.c++", "shell":false, "working_dir" : "$file_path", "variants": [ { "name": "RunInCommand", "cmd": ["cmd", "/c", "gcc","-g", "${file}", "-o", "${file_path}/${file_base_name}", "&&","start", "cmd", "/k", "${file_path}/${file_base_name}"] } ] }
C++编译器,支持GDB
{ "cmd" : ["g++", "$file_name", "-o", "${file_base_name}", "-lm", "-Wall"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "selector" : "source.c, source.c++", "shell":false, "working_dir" : "$file_path", "variants": [ { "name": "RunInCommand", "cmd": ["cmd", "/c", "g++","-g", "${file}", "-o", "${file_path}/${file_base_name}", "&&","start", "cmd", "/k", "${file_path}/${file_base_name}"] } ] }
Java编译器
{ "cmd" : ["javac", "$file_name"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "selector" : "source.java", "shell":false, "working_dir" : "$file_path", "variants": [ { "name": "RunInCommand", "cmd": ["cmd", "/c", "javac","${file}","&&","start", "cmd", "/k", "java $file_name"] } , { "name":"Debug", "cmd": ["cmd", "/c","javac","${file}","&&","start", "cmd", "/k","gdb ${file_path}/${file_base_name}"] } ] }
由于我常用这三种语言暂时就配置了这三种语言,其他语言可以参考这三种配置,原理都一样,编译完直接使用命令提示符打开不用它自带的那个终端显示