以下配置都在GoSublime插件的Settings - User 配置里面设置。
1.自动导包(go get -v code.google.com/p/go.tools/cmd/goimports):
“fmt_cmd”: [“goimports”],
2.自动编译包:
"comp_lint_enabled":true,
"comp_lint_commands": [
{"cmd": ["go", "install"]}
],
"lint_enabled": true,
"on_save": [{"cmd":"gs_comp_lint"}],
3.提示内置关键字:
"autocomplete_builtins": true,
4.收集的代码片段:
"snippets": [
{
"match": {"global": true, "pkgname": "."},
"snippets": [
{
"text":"type",
"title":"type struct {}",
"value":"type ${1:name} struct {\n\t$0\n}"
},{
"text":"type",
"title":"type interface {}",
"value":"type ${1:name} interface {\n\t$0\n}"
},{
"text":"var",
"title":"var struct {}",
"value":"var ${1:name} struct {\n\t$0\n}"
},{
"text":"map",
"title":"map[...]...",
"value":"map[${1:string}]${2:interface{}}"
},{
"text":"interface",
"title":"interface{}",
"value":"interface{}"
},{
"text":"if",
"title":"if err != nil {...}",
"value":"if ${1:err} ${2:!=} ${3:nil} {\n\t$0\n}"
},{
"text":"if",
"title":"if ret,ok := func(); ok {...}",
"value":"if ${1:ret,} ${2:ok} ${3::=} ${4:func()}; ${5:!ok} {\n\t$0\n}"
},{
"text":"break",
"title":"break",
"value":"break"
},{
"text":"continue",
"title":"continue",
"value":"continue"
},{
"text":"defer",
"title":"defer func()",
"value":"defer ${0:func()}"
},{
"text":"for",
"title":"for k,v := range func() {...}",
"value":"for ${1:k,}${2:v} := range ${3:func()} {\n\t$0\n}"
},{
"text":"switch",
"title":"switch ... {...}",
"value":"switch ${1:name} {\ncase ${2:v}:\n\t$3\ndefault:\n\t$0\n}"
}
]
}
],
5.代码导航和跳转(go get -v code.google.com/p/rog-go/exp/cmd/godef):
安装ST3插件:godef
设置工作目录(Settings - User):{“gopath”: “/home/guozi/works/goworks”}
设置快捷键(Key Bindings - Default):
[{ "keys": ["super+h"], "command": "godef" },
{ "keys": ["super+j"], "command": "jump_forward"},
{ "keys": ["super+k"], "command": "jump_back"} ]
6.常用快捷键:
ctrl+.+p 搜索包路径并插入到当前文件的import()
ctrl+shift+鼠标左键 代码导航跳转
ctrl+.+n 新建go源文件
super+h 高级导航跳转
7.其他扩展
terminal插件,在当前路径打开一个终端