1
0
Fork 0
mirror of synced 2024-11-30 04:35:35 -05:00
ultimate-vim/sources_non_forked/vim-snippets/UltiSnips/go.snippets

116 lines
2.1 KiB
Text
Raw Normal View History

2012-08-16 23:41:25 -04:00
# Snippets for Go
priority -50
2012-08-16 23:41:25 -04:00
# when to abbriviate and when not?
# b doesn't work here, because it ignores whitespace
# optional local name?
snippet /^import/ "Import declaration" r
import (
"${1:package}"
)
endsnippet
snippet /^package/ "Package declaration" r
// Package $1 provides ...
package ${1:main}
endsnippet
# Mostly converted from: https://github.com/AlanQuatermain/go-tmbundle
snippet /^cons/ "Constants declaration" r
const (
${1:constant}${2/(.+)/ /}${2:type} = ${0:value}
)
endsnippet
snippet /^con/ "Constant declaration" r
const ${1:name}${2/(.+)/ /}${2:type} = ${0:value}
endsnippet
snippet iota "Iota constant generator" b
const (
${1:constant}${2/(.+)/ /}${2:type} = iota
)
endsnippet
snippet struct "Struct declaration" b
type ${1:Struct} struct {
${0:${VISUAL}}
}
endsnippet
snippet interface "Interface declaration" b
type ${1:Interface} interface {
${0:${VISUAL}}
}
endsnippet
snippet if "If statement" b
2012-08-16 23:41:25 -04:00
if ${1:condition}${1/(.+)/ /}{
${0:${VISUAL}}
}
endsnippet
snippet switch "Switch statement" b
2012-08-16 23:41:25 -04:00
switch ${1:expression}${1/(.+)/ /}{
2017-02-11 08:01:38 -05:00
case$0
2012-08-16 23:41:25 -04:00
}
endsnippet
# functions
snippet /^main/ "Main function" r
func main() {
${0:${VISUAL}}
}
endsnippet
snippet /^meth/ "Method" r
func (${1:receiver} ${2:type}) ${3:name}(${4:params})${5/(.+)/ /}${5:type} {
${0:${VISUAL}}
}
endsnippet
snippet func "Function" b
func ${1:name}(${2:params})${3/(.+)/ /}${3:type} {
${0:${VISUAL}}
}
endsnippet
2015-03-14 16:02:10 -04:00
snippet funch "HTTP handler" b
func ${1:handler}(${2:w} http.ResponseWriter, ${3:r} *http.Request) {
${0:${VISUAL}}
}
endsnippet
2012-08-16 23:41:25 -04:00
# types and variables
snippet map "Map type" b
2012-08-16 23:41:25 -04:00
map[${1:keytype}]${2:valtype}
endsnippet
snippet : "Variable declaration :=" b
2012-08-16 23:41:25 -04:00
${1:name} := ${0:value}
endsnippet
snippet var "Variable declaration" b
2012-08-16 23:41:25 -04:00
var ${1:name}${2/(.+)/ /}${2:type}${3: = ${0:value}}
endsnippet
snippet vars "Variables declaration" b
2012-08-16 23:41:25 -04:00
var (
${1:name}${2/(.+)/ /}${2:type}${3: = ${0:value} }
)
endsnippet
snippet json "JSON field"
\`json:"${1:displayName}"\`
endsnippet
2012-08-16 23:41:25 -04:00
# vim:ft=snippets:
2015-03-14 16:02:10 -04:00
# error handling
snippet err "Basic error handling" b
if err != nil {
log.${1:Fatal}(err)
}
endsnippet