vim-snippets/snippets/go.snippets

215 lines
3.3 KiB
Plaintext
Raw Normal View History

2011-06-22 03:44:04 -04:00
# append
snippet ap
append(${1:slice}, ${2:value})
2011-06-24 04:09:28 -04:00
# bool
snippet bl
bool
2011-06-22 03:44:04 -04:00
# 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 ${1: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}:
${2:/* code */}
# const
snippet c
const ${1:NAME} = ${2: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
${2:NAME2}
)
# continue
snippet cn
continue
# defer
snippet df
defer ${1:func}()
# defer recover
snippet dfr
defer func() {
if err := recover(); err != nil {
${1:/* code */}
}
}()
# 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) ${1:Author}, `strftime("%Y")`
*/
${2}
# int
snippet i
int
# import
snippet im
import (
"${1:package}"
2013-02-12 04:12:58 -05:00
)${2}
2011-06-22 03:44:04 -04:00
# interface
snippet in
interface{}
# full interface snippet
snippet inf
interface ${1:name} {
${2:/* methods */}
}${3}
# if condition
snippet if
if ${1:/* condition */} {
${2:/* code */}
2013-02-12 04:12:58 -05:00
}${2}
2011-06-22 03:44:04 -04:00
# else snippet
snippet el
else {
${1}
2013-02-12 04:12:58 -05:00
}${2}
2011-06-22 03:44:04 -04:00
# error snippet
snippet ir
if err != nil {
return err
}
${1}
# 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:/* code */}
} else {
${3}
}
2013-02-12 04:12:58 -05:00
${4}
2011-06-22 03:44:04 -04:00
# for loop
snippet fo
for ${2:i} = 0; $2 < ${1:count}; $2${3:++} {
${4:/* code */}
}
2013-02-12 04:12:58 -05:00
${5}
2011-06-22 03:44:04 -04:00
# for range loop
snippet fr
for ${1:k}, ${2:v} := range ${3} {
${4:/* code */}
}
2013-02-12 04:12:58 -05:00
${5}
2011-06-22 03:44:04 -04:00
# function simple
snippet fun
func ${1:funcName}(${2}) ${3:error} {
2011-06-22 03:44:04 -04:00
${4:/* code */}
}
2013-02-12 04:12:58 -05:00
${5}
2011-06-22 03:44:04 -04:00
# function on receiver
snippet fum
func (self ${1:type}) ${2:funcName}(${3}) ${4:error} {
2011-06-22 03:44:04 -04:00
${5:/* code */}
}
${6}
# log printf
snippet lf
log.Printf("%${1:s}", ${2:var})${3}
# log printf
snippet lp
log.Println("${1}")${2}
2011-06-22 03:44:04 -04:00
# make
snippet mk
make(${1:[]string}, ${2:0})
# map
snippet mp
map[${1:string}]${2:int}
# main()
snippet main
func main() {
${1:/* code */}
}
2013-02-12 04:12:58 -05:00
${2}
2011-06-22 03:44:04 -04:00
# new
snippet nw
new(${1:type})
# panic
snippet pn
panic("${1:msg}")
# print
snippet pr
fmt.Printf("%${1:s}\n", ${2:var})${3}
2011-06-22 03:44:04 -04:00
# range
snippet rn
range ${1}
# return
snippet rt
return ${1}
# result
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:/* code */}
case ${4:v2} := <-${5:chan2}
${6:/* code */}
default:
${7:/* code */}
}
# string
snippet sr
string
# struct
snippet st
struct ${1:name} {
${2:/* data */}
2013-02-12 04:12:58 -05:00
}
${3}
2011-06-22 03:44:04 -04:00
# switch
snippet sw
switch ${1:var} {
case ${2:value1}:
${3:/* code */}
case ${4:value2}:
${5:/* code */}
default:
${6:/* code */}
}
snippet sp
fmt.Sprintf("%${1:s}", ${2:var})${3}
2011-06-22 03:44:04 -04:00
# true
2011-06-24 04:09:28 -04:00
snippet t
2011-06-22 03:44:04 -04:00
true
# variable declaration
snippet v
var ${1:t} ${2:string}