You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
275 lines
4.6 KiB
Plaintext
275 lines
4.6 KiB
Plaintext
10 years ago
|
# shorthand variable declaration
|
||
|
snippet :
|
||
|
abbr v := value
|
||
|
${1} := ${0}
|
||
|
# anonymous function
|
||
|
snippet anon
|
||
|
abbr fn := func() { ... }
|
||
|
${1:fn} := func() {
|
||
|
${0}
|
||
|
}
|
||
|
# append
|
||
|
snippet ap
|
||
|
abbr append(slice, value)
|
||
|
append(${1:slice}, ${0:value})
|
||
|
# break
|
||
|
snippet br
|
||
|
abbr break
|
||
|
break
|
||
|
# channel
|
||
|
snippet ch
|
||
|
abbr chan Type
|
||
|
chan ${0:int}
|
||
|
# case
|
||
|
snippet case
|
||
|
abbr case ...:
|
||
|
case ${1:value}:
|
||
|
${0}
|
||
|
# constant
|
||
|
snippet con
|
||
|
abbr const XXX Type = ...
|
||
|
const ${1:NAME} ${2:Type} = ${0:0}
|
||
|
# constants
|
||
|
snippet cons
|
||
|
abbr const ( ... )
|
||
|
const (
|
||
|
${1:NAME} ${2:Type} = ${3:value}
|
||
|
${0}
|
||
|
)
|
||
|
# constants with iota
|
||
|
snippet iota
|
||
|
abbr const ( ... = iota )
|
||
|
const (
|
||
|
${1:NAME} ${2:Type} = iota
|
||
|
${0}
|
||
|
)
|
||
|
# continue
|
||
|
snippet cn
|
||
|
abbr continue
|
||
|
continue
|
||
|
# default case
|
||
|
snippet default
|
||
|
abbr default: ...
|
||
|
default:
|
||
|
${0}
|
||
|
|
||
|
# defer
|
||
|
snippet df
|
||
|
abbr defer someFunction()
|
||
|
defer ${1:func}(${2})
|
||
|
${0}
|
||
|
snippet def
|
||
|
abbr defer func() { ... }
|
||
|
defer func() {
|
||
|
${0}
|
||
|
}()
|
||
|
# defer recover
|
||
|
snippet defr
|
||
|
defer func() {
|
||
|
if err := recover(); err != nil {
|
||
|
${0}
|
||
|
}
|
||
|
}()
|
||
|
# gpl
|
||
|
snippet gpl
|
||
|
/*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
* Copyright (C) ${1:Author}, `strftime("%Y")`
|
||
|
*/
|
||
|
|
||
|
${0}
|
||
|
# import
|
||
|
snippet import
|
||
|
abbr import ( ... )
|
||
|
import (
|
||
|
"${1:package}"
|
||
|
)
|
||
|
# full interface snippet
|
||
|
snippet interface
|
||
|
abbr interface I { ... }
|
||
|
type ${1:Interface} interface {
|
||
|
${2:/* TODO: add methods */}
|
||
|
}
|
||
|
# if condition
|
||
|
snippet if
|
||
|
abbr if ... { ... }
|
||
|
if ${1:condition} {
|
||
|
${0}
|
||
|
}
|
||
|
# else snippet
|
||
|
abbr else { ... }
|
||
|
snippet else
|
||
|
else {
|
||
|
${0}
|
||
|
}
|
||
|
# error snippet
|
||
|
snippet errn
|
||
|
abbr if err != nil { ... }
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
# error snippet with two return values
|
||
|
snippet errn,
|
||
|
abbr if err != nil { return [...], err }
|
||
|
if err != nil {
|
||
|
return ${2}$1, err
|
||
|
}
|
||
|
${0}
|
||
|
|
||
|
# json snippet
|
||
|
snippet json
|
||
|
abbr \`json:key\`
|
||
|
\`json:"${1:keyName}"\`
|
||
|
# fallthrough
|
||
|
snippet ft
|
||
|
abbr fallthrough
|
||
|
fallthrough
|
||
|
# for loop
|
||
|
snippet for
|
||
|
abbr for ... { ... }
|
||
|
for ${1} {
|
||
|
${0}
|
||
|
}
|
||
|
# for integer loop
|
||
|
snippet fori
|
||
|
abbr for 0..N-1 { ... }
|
||
|
for ${1:i} := 0; $1 < ${2:N}; $1++ {
|
||
|
${0}
|
||
|
}
|
||
|
# for range loop
|
||
|
snippet forr
|
||
|
abbr for k, v := range items { ... }
|
||
|
for ${2:k}, ${3:v} := range ${1} {
|
||
|
${0}
|
||
|
}
|
||
|
# function
|
||
|
snippet func
|
||
|
abbr func function(...) [error] { ... }
|
||
|
func ${1:function}(${2}) ${3:error }{
|
||
|
${0}
|
||
|
}
|
||
|
# Fmt Printf debug
|
||
|
snippet ff
|
||
|
abbr fmt.Printf(...)
|
||
|
fmt.Printf("${1} = %+v\n", $1)
|
||
|
${0}
|
||
|
# Fmt Println debug
|
||
|
snippet fn
|
||
|
abbr fmt.Println(...)
|
||
|
fmt.Println("${1}")
|
||
|
# log printf
|
||
|
snippet lf
|
||
|
abbr log.Printf(...)
|
||
|
log.Printf("${1} = %+v\n", $1)
|
||
|
# log println
|
||
|
snippet ln
|
||
|
abbr log.Println(...)
|
||
|
log.Println("${1}")
|
||
|
# make
|
||
|
snippet make
|
||
|
abbr make(Type, size)
|
||
|
make(${1:[]string}, ${2:0})${0}
|
||
|
# map
|
||
|
snippet map
|
||
|
abbr map[Type]Type
|
||
|
map[${1:string}]${0:int}
|
||
|
# main()
|
||
|
snippet main
|
||
|
abbr func main() { ... }
|
||
|
options head
|
||
|
func main() {
|
||
|
${0}
|
||
|
}
|
||
|
# method
|
||
|
snippet meth
|
||
|
abbr func (self Type) Method(...) [error] { ... }
|
||
|
regexp /^meth/
|
||
|
func (${1:self} ${2:Type}) ${3:Do}(${4}) ${5:error }{
|
||
|
${0}
|
||
|
}
|
||
|
# ok
|
||
|
snippet ok
|
||
|
abbr if !ok { ... }
|
||
|
if !ok {
|
||
|
${0}
|
||
|
}
|
||
|
# package
|
||
|
snippet package
|
||
|
abbr package ...
|
||
|
// Package $1 provides ${2:...}
|
||
|
package ${1:main}
|
||
|
${0}
|
||
|
# panic
|
||
|
snippet panic
|
||
|
alias pn
|
||
|
abbr panic("...")
|
||
|
panic("${0}")
|
||
|
# return
|
||
|
snippet return
|
||
|
alias rt
|
||
|
abbr return ...
|
||
|
return ${0}
|
||
|
# select
|
||
|
snippet select
|
||
|
abbr select { case a := <-chan: ... }
|
||
|
select {
|
||
|
case ${1:v1} := <-${2:chan1}
|
||
|
${0}
|
||
|
}
|
||
|
# struct
|
||
|
snippet st
|
||
|
abbr type T struct { ... }
|
||
|
type ${1:Type} struct {
|
||
|
${0}
|
||
|
}
|
||
|
# switch
|
||
|
snippet switch
|
||
|
abbr switch x { ... }
|
||
|
switch ${1:var} {
|
||
|
case ${2:value1}:
|
||
|
${0}
|
||
|
}
|
||
|
# sprintf
|
||
|
snippet sp
|
||
|
abbr fmt.Sprintf(...)
|
||
|
fmt.Sprintf("%${1:s}", ${2:var})
|
||
|
# goroutine named function
|
||
|
snippet go
|
||
|
abbr go someFunc(...)
|
||
|
go ${1:funcName}(${0})
|
||
|
# goroutine anonymous function
|
||
|
snippet gof
|
||
|
abbr go func(...) { ... }(...)
|
||
|
go func(${1}) {
|
||
|
${3:/* TODO */}
|
||
|
}(${2})
|
||
|
# test function
|
||
|
snippet test
|
||
|
abbr func TestXYZ(t *testing.T) { ... }
|
||
|
func Test${1:Function}(t *testing.T) {
|
||
|
${0}
|
||
|
}
|
||
|
# variable declaration
|
||
|
snippet var
|
||
|
abbr var x Type [= ...]
|
||
|
var ${1:x} ${2:Type}${3: = ${0:value\}}
|
||
|
# variables declaration
|
||
|
snippet vars
|
||
|
abbr var ( ... )
|
||
|
var (
|
||
|
${1:x} ${2:Type}${3: = ${0:value\}}
|
||
|
)
|