sublime对应语言模板使用技巧
# 前言
sublime 作为一个比较便捷的文本工具,颜值非常高,编写基本工具时候如果不需要打开IDE,可以将这个工具作为第一个选择 !!!
不要跟我说 devCPP,vscode, editplus...
这部分内容是纪录sublime
工具破解以及编写对应语言自定义编译命令
# 使用步骤
基本步骤
- tools->build system->new build system-> xxx.sublime-build (根据自己定义命令,后面会用到)-> save->
- 使用 tools->build system->找到刚刚保存的选择
# 模板
java
{
// Windows
// "shell_cmd": "javac -d ${file_path}/../bin/ -sourcepath ${file} ",
"shell_cmd": "javac ${file} -d bin -encoding utf-8 && cd bin && java ${file_base_name} ",
// check the file name using regex
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
// set the encoding to utf-8
"encoding": "GBK",
// doesn't matter if I use full path
"working_dir": "${file_path}",
// only java files can use this sublime-build file
"selector": "source.java",
"variants": [
{
// build and run in CMD
// you can type something in CMD then your progam can get its inputs
// [Recommanded]
"name": "Run in CMD",
"shell_cmd": "start cmd /c IF NOT EXIST bin MKDIR bin && javac -d bin ${file} && cd bin && start cmd /K java ${file_base_name}"
},
{
// build and run in sublime
// but you can't input anything to your progam
"name": "Run in Sublime",
"shell_cmd": "javac -d bin ${file} && cd bin && java ${file_base_name} "
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
当然配套的也可以自定义了,使用我下面这个模板可以快速创建类coding了……
import java.util.*;
import java.io.*;
import java.lang.reflect.*;
public class Code00 {
private static String root_dir = null;
private static final File file = new File("");
private static final String compileDir = "bin";
static {
String path = file.getAbsolutePath();
if(path.contains(compileDir)){
path = path.replace(compileDir,"");
}
root_dir = path;
}
public static void main(String[] args) {
int cnt = countJavaFile();
String fileName ="Code"+(cnt < 10 ? ("0" + cnt):String.valueOf(cnt)) + ".java";
String javaFilePath = root_dir + fileName;
String template = content(fileName);
readContent(template,javaFilePath);
}
public static int countJavaFile(){
int ans = 0;
File f = new File(root_dir);
File[] fs = f.listFiles();
for(File temp : fs ){
if(temp.getAbsolutePath().endsWith(".java")){
ans++;
}
}
return ans;
}
public static void readContent(String content,String javaFilePath){
try{
File file = new File(javaFilePath);
if(!file.exists()){
file.createNewFile();
}
BufferedWriter w = new BufferedWriter(new FileWriter(file));
w.write(content,0,content.length());
w.flush();
w.close();
System.out.println(javaFilePath + " create success !");
}catch(Exception e){
e.printStackTrace();
}
}
public static void printMethodInfo(Class<?> c){
Method[] mts = c.getDeclaredMethods();
for(Method m : mts){
System.out.println("\n"+m+"\n");
}
}
public static String content(String className){
if(className == null || className.length() == 0){
throw new NullPointerException("className is null");
}
if(className.endsWith(".java")){
className = className.replace(".java","");
}
StringBuilder sb = new StringBuilder();
sb.append("import java.util.*; \n\n");
sb.append("public class ").append(className).append(" {");
sb.append("\n public static void main(String[] args) {\n\n");
sb.append(" ");
sb.append(className);
sb.append(" code = new ");
sb.append(className);
sb.append("(); \n\n\n");
sb.append(" }\n");
sb.append("}");
return sb.toString();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
C++
{
// Windows
// build only
"shell_cmd": "g++ -std=c++11 -g -Wall ${file} -o ${file_path}/../bin/${file_base_name}",
// check the file name using regex
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
// set the encoding to utf-8
"encoding": "utf-8",
// doesn't matter if I use full path
"working_dir": "${file_path}",
// only C and Cpp files can use this sublime-build file
"selector": "source.c, source.c++",
"variants": [
{
// build and run in Terminus (sublime plugin)
// [Recommanded]
"name": "Run In Terminus",
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"shell_cmd": "g++ -std=c++11 -g -Wall \"${file}\" -o \"${file_path}/../bin/${file_base_name}\" && cmd /c \"${file_path}/../bin/${file_base_name}\""
},
{
// build and run in CMD
// you can type something in CMD then your progam can get its inputs
// [Recommanded]
"name": "Run in CMD",
"shell_cmd": "g++ -std=c++11 -g -Wall \"${file}\" -o \"${file_path}/../bin/${file_base_name}\" && start cmd /c \"\"${file_path}/../bin/${file_base_name}\" & pause \""
},
{
// build and run in sublime
// but you can't input anything to your progam
"name": "Run in Sublime",
"shell_cmd": "g++ -std=c++11 -g -Wall \"${file}\" -o \"${file_path}/../bin/${file_base_name}\" && cmd /c \"${file_path}/../bin/${file_base_name}\""
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
C
{
// Windows
// build only
"shell_cmd": "gcc -std=c99 -g -Wall ${file} -o ${file_path}/../bin/${file_base_name}",
// check the file name using regex
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
// set the encoding to utf-8
"encoding": "utf-8",
// doesn't matter if I use full path
"working_dir": "${file_path}",
// only C and Cpp files can use this sublime-build file
"selector": "source.c",
"variants": [
{
// build and run in Terminus (sublime plugin)
// [Recommanded]
"name": "Run In Terminus",
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"shell_cmd": "gcc -std=c99 -g -Wall \"${file}\" -o \"${file_path}/../bin/${file_base_name}\" && cmd /c \"${file_path}/../bin/${file_base_name}\""
},
{
// build and run in CMD
// you can type something in CMD then your progam can get its inputs
// [Recommanded]
"name": "Run in CMD",
"shell_cmd": "gcc -std=c99 -g -Wall \"${file}\" -o \"${file_path}/../bin/${file_base_name}\" && start cmd /c \"\"${file_path}/../bin/${file_base_name}\" & pause \""
},
{
// build and run in sublime
// but you can't input anything to your progam
"name": "Run in Sublime",
"shell_cmd": "gcc -std=c99 -g -Wall \"${file}\" -o \"${file_path}/../bin/${file_base_name}\" && cmd /c \"${file_path}/../bin/${file_base_name}\""
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Go
{
// Windows
// "shell_cmd": "javac -d ${file_path}/../bin/ -sourcepath ${file} ",
"shell_cmd": "go run ${file}",
// check the file name using regex
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
// set the encoding to utf-8
"encoding": "utf-8",
// doesn't matter if I use full path
"working_dir": "${file_path}",
// only java files can use this sublime-build file
"selector": "source.go",
"variants": [
{
// build and run in CMD
// you can type something in CMD then your progam can get its inputs
// [Recommanded]
"name": "Run in CMD",
"shell_cmd": "start cmd /K go run ${file_name}"
},
{
// build and run in sublime
// but you can't input anything to your progam
"name": "Run in Sublime",
"shell_cmd": "go run ${file_name}"
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
补充
如果上面有了上面模板不能满足需求,可根据上面模板自己调整,应该都能调试出自己想要的模板
如果不想使用模板可以使用shell脚本
example
#!/bin/bash
filename=$1
workdir=$(pwd)/bin
if [ ! -d "bin" ]; then
mkdir bin
fi
javac -d bin -encoding GBK $(pwd)/${filename}.java && cd bin && java ${filename} 2>>err.txt
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
使用
sh xx.sh 类名
1
# 激活教程
# 字体管理
如果不喜欢默认字体,推荐几个好的字体
- jetbrains mono (jetbranisn 全家桶的)
- fira code
- roboto mono
- monaco
字体下载
更换系统字体
如果更换系统字体 ? 点我下载 (opens new window)
更换sublime编辑器字体
preferences->foot->choose
注意
下载的字体不要忘记安装了哦!
# 推荐链接
编辑 (opens new window)
上次更新: 2024-04-04, 21:49:53