vim-snippets/snippets/go.snippets

247 lines
3.6 KiB
Plaintext
Raw Normal View History

# shorthand variable declaration
snippet v
${1} := ${2}
# variable initialization
snippet vr
var ${1:t} ${0:string}
# variable declaration
snippet var
var ${1} ${2} = ${3}
# variables declaration
snippet vars
var (
${1} ${2} = ${3}
)
2011-06-22 03:44:04 -04:00
# append
snippet ap
append(${1:slice}, ${0:value})
2011-06-24 04:09:28 -04:00
# bool
snippet bl
bool
# byte
2011-06-24 04:09:28 -04:00
snippet bt
2011-06-22 03:44:04 -04:00
byte
# break
snippet br
break
# channel
snippet ch
chan ${0:int}
2011-06-24 04:09:28 -04:00
# case
2011-06-22 03:44:04 -04:00
snippet cs
2011-06-24 04:09:28 -04:00
case ${1:value}:
${0}
2011-06-24 04:09:28 -04:00
# const
snippet c
const ${1:NAME} = ${0:0}
2011-06-22 03:44:04 -04:00
# constants with iota
2011-06-24 04:09:28 -04:00
snippet co
2011-06-22 03:44:04 -04:00
const (
${1:NAME1} = iota
${0:NAME2}
2011-06-22 03:44:04 -04:00
)
# continue
snippet cn
continue
# defer
2011-06-22 03:44:04 -04:00
snippet df
defer ${0:func}()
2011-06-22 03:44:04 -04:00
# defer recover
snippet dfr
defer func() {
if err := recover(); err != nil {
${0}
2011-06-22 03:44:04 -04:00
}
}()
# 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/>.
2011-06-22 03:44:04 -04:00
*
* Copyright (C) ${1:Author}, `strftime("%Y")`
*/
${0}
2011-06-22 03:44:04 -04:00
# int
snippet i
int
# import
2011-06-22 03:44:04 -04:00
snippet im
import (
"${1:package}"
)
# interface
2011-06-22 03:44:04 -04:00
snippet in
interface{}
# full interface snippet
2011-06-22 03:44:04 -04:00
snippet inf
interface ${1:name} {
${2:/* methods */}
}
2011-06-22 03:44:04 -04:00
# if condition
snippet if
if ${1:/* condition */} {
${2}
}
2011-06-22 03:44:04 -04:00
# else snippet
snippet el
else {
${1}
}
2011-06-22 03:44:04 -04:00
# error snippet
snippet ir
if err != nil {
return err
}
${0}
2011-06-22 03:44:04 -04:00
# false
2011-06-24 04:09:28 -04:00
snippet f
2011-06-22 03:44:04 -04:00
false
# fallthrough
2011-06-24 04:09:28 -04:00
snippet ft
2011-06-22 03:44:04 -04:00
fallthrough
# float
snippet fl
float32
2011-06-24 04:09:28 -04:00
# float32
snippet f3
float32
# float64
snippet f6
float64
2011-06-22 03:44:04 -04:00
# if else
snippet ie
if ${1:/* condition */} {
${2}
2011-06-22 03:44:04 -04:00
} else {
${3}
}
${0}
2011-06-22 03:44:04 -04:00
# for loop
snippet fo
2013-03-23 18:09:49 -04:00
for ${2:i} := 0; $2 < ${1:count}; $2${3:++} {
${4}
2011-06-22 03:44:04 -04:00
}
${0}
2011-06-22 03:44:04 -04:00
# for range loop
snippet fr
for ${1:k}, ${2:v} := range ${3} {
${4}
2011-06-22 03:44:04 -04:00
}
${0}
# function simple
2011-06-22 03:44:04 -04:00
snippet fun
func ${1:funcName}(${2}) ${3:error} {
${4}
2011-06-22 03:44:04 -04:00
}
${0}
# function on receiver
2011-06-22 03:44:04 -04:00
snippet fum
func (self ${1:type}) ${2:funcName}(${3}) ${4:error} {
${5}
2011-06-22 03:44:04 -04:00
}
${0}
# log printf
snippet lf
log.Printf("%${1:s}", ${2:var})
# log printf
snippet lp
log.Println("${1}")
2011-06-22 03:44:04 -04:00
# make
snippet mk
make(${1:[]string}, ${0:0})
# map
2011-06-22 03:44:04 -04:00
snippet mp
map[${1:string}]${0:int}
2011-06-22 03:44:04 -04:00
# main()
snippet main
func main() {
${1}
2011-06-22 03:44:04 -04:00
}
${0}
2011-06-22 03:44:04 -04:00
# new
snippet nw
new(${0:type})
# panic
2011-06-22 03:44:04 -04:00
snippet pn
panic("${0:msg}")
2011-06-22 03:44:04 -04:00
# print
snippet pr
fmt.Printf("%${1:s}\n", ${2:var})
# range
2011-06-22 03:44:04 -04:00
snippet rn
range ${0}
# return
2011-06-22 03:44:04 -04:00
snippet rt
return ${0}
# result
2011-06-22 03:44:04 -04:00
snippet rs
result
# select
2011-06-24 04:09:28 -04:00
snippet sl
2011-06-22 03:44:04 -04:00
select {
case ${1:v1} := <-${2:chan1}
${3}
2011-06-22 03:44:04 -04:00
case ${4:v2} := <-${5:chan2}
${6}
2011-06-22 03:44:04 -04:00
default:
${0}
2011-06-22 03:44:04 -04:00
}
# string
snippet sr
string
# struct
snippet st
struct ${1:name} {
${2:/* data */}
2013-02-12 04:12:58 -05:00
}
${0}
# switch
2011-06-22 03:44:04 -04:00
snippet sw
switch ${1:var} {
case ${2:value1}:
${3}
2011-06-22 03:44:04 -04:00
case ${4:value2}:
${5}
2011-06-22 03:44:04 -04:00
default:
${0}
2011-06-22 03:44:04 -04:00
}
snippet sp
fmt.Sprintf("%${1:s}", ${2:var})
# true
2011-06-24 04:09:28 -04:00
snippet t
2011-06-22 03:44:04 -04:00
true
# goroutine named function
snippet g
go ${1:funcName}(${0})
# goroutine anonymous function
snippet ga
go func(${1} ${2:type}) {
${3:/* code */}
}(${0})
# test function
snippet tst
func Test${1:name}(t *testing.T) {
${2}
}
${0}
# benchmark function
snippet bnch
func Benchmark${1:name}(b *testing.B) {
for i := 0; i < b.N; i++ {
${2}
}
}
${0}