使用sublime在cmd成功运行c/c++、java代码。本机环境:win8.1、sublime text 3、jkd1.8.0_25、CodeBlocks/MinGw
1、点击Tools->Build System->new Build System。添加如下内容:
<pre name="code" class="plain">{ "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "selector": "source.c, source.c++", "working_dir": "${file_path}", "variants": [ { "name": "Run", "cmd": ["cmd", "/c", "g++", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & pause"] }, { "name": "RunInCommand", "cmd": ["cmd", "/c", "g++", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & pause"] } ] }
保存为My_C++.sublime-build并退出。
2、点击Tools->Build System->new Build System。添加如下内容:
{ "cmd": ["javac","${file}"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.java", "working_dir": "${file_path}", "variants": [ { "name": "Run","shell": true, "cmd" : ["cmd","/c", "javac","$file","&&", "start", "cmd", "/c", "java ${file_base_name} &pause"] }, { "name": "RunInCommand","shell": true, "cmd" : ["cmd","/c", "javac","$file","&&", "start", "cmd", "/c", "java ${file_base_name} & pause"] } ] }保存为My_java.sublime-build并退出。
3、在Preferences->Key Bindings - User中添加如下内容:
[ <span style="white-space:pre"> </span>{ "keys": ["f10"], "command": "build", "args": {"variant": "RunInCommand"} } ]保存。
4、然后,如果你想要编译运行C/C++代码,选择Tools->Build System->My_C++;如果想编译运行java代码,选择Tools->Build System->My_java;按F10和ctrl+shift+b都行。
5、自定义配置按键模拟vim
打开sublime->preferences->Key Bindings-User。
添加如下内容:
[ { "keys": ["alt+l"], "command": "move", "args": {"by": "characters", "forward": true} }, { "keys": ["alt+h"], "command": "move", "args": {"by": "characters", "forward": false} }, { "keys": ["alt+j"], "command": "move", "args": {"by": "lines", "forward": true} }, { "keys": ["alt+k"], "command": "move", "args": {"by": "lines", "forward": false} } ]保存即可。
6、开启、关闭自动换行
打开sublime->preferences->Settings-User。
添加如下内容:
[ "word_wrap" : false//关闭自动换行 "word_wrap" : true//打开自动换行 ]保存即可。
另外,在View->Word Wrap处也可设置。
7、添加自己的代码模板,让写代码更方便
Tools->New Snippet粘贴保存snippte.cpp
/** **author :Or_me ** ╭︿︿︿╮ {/ a c /} ( (oo) ) ︶︶︶ ** ** ** 题** ** 2014 年 月 日** **/ #include <set> #include <map> #include <cmath> #include <queue> #include <stack> #include <vector> #include <cstdio> #include <string> #include <cctype> #include <climits> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; int main() { //freopen("Input.txt","r",stdin); //freopen("Output.txt"."w",stdout); system("color 5b"); return 0; }