1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 01:25:00 +08:00

Updated plugins

This commit is contained in:
amix
2015-01-18 12:58:28 +00:00
parent c3ba0f3c06
commit e7a01094b6
274 changed files with 4547 additions and 3075 deletions

View File

@ -2,151 +2,143 @@
priority -10
# when to abbriviate and when not?
# b doesn't work here, because it ignores whitespace
# optional local name?
snippet import "Import declaration" b
# shorthand variable declaration
snippet : "v := value"
${1} := ${0}
endsnippet
# anonymous function
snippet anon "fn := func() { ... }"
${1:fn} := func() {
${0}
}
endsnippet
# append
snippet ap "append(slice, value)"
append(${1:slice}, ${0:value})
endsnippet
# break
snippet br "break"
break
endsnippet
# channel
snippet ch "chan Type"
chan ${0:int}
endsnippet
# case
snippet case "case ...:"
case ${1:value}:
${0}
endsnippet
# constant
snippet con "const XXX Type = ..."
const ${1:NAME} ${2:Type} = ${0:0}
endsnippet
# constants
snippet cons "const ( ... )"
const (
${1:NAME} ${2:Type} = ${3:value}
${0}
)
endsnippet
# constants with iota
snippet iota "const ( ... = iota )"
const (
${1:NAME} ${2:Type} = iota
${0}
)
endsnippet
# continue
snippet cn "continue"
continue
endsnippet
# default case
snippet default "default: ..."
default:
${0}
endsnippet
# defer
snippet df "defer someFunction()"
defer ${1:func}(${2})
${0}
endsnippet
snippet def "defer func() { ... }"
defer func() {
${0}
}()
endsnippet
# defer recover
snippet defr
defer func() {
if err := recover(); err != nil {
${0}
}
}()
endsnippet
# 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}
endsnippet
# import
snippet import "import ( ... )"
import (
"${1:package}"
)
endsnippet
snippet package "Package declaration" b
// Package $1 provides ${2:...}
package ${1:main}
${0:${VISUAL}}
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
# full interface snippet
snippet interface "interface I { ... }"
type ${1:Interface} interface {
${0:${VISUAL}}
${2:/* TODO: add methods */}
}
endsnippet
# statements
snippet for "For loop" b
for ${1:condition} {
${0:${VISUAL}}
}
endsnippet
snippet fori "Integer for loop" b
for ${1:i} := 0; $1 < ${2:N}; $1++ {
${0:${VISUAL}}
}
endsnippet
snippet forr "For range loop" b
for ${2:name} := range ${1:collection} {
${0:${VISUAL}}
}
endsnippet
snippet if "If statement" b
if ${1:condition}${1/(.+)/ /}{
${0:${VISUAL}}
}
endsnippet
snippet switch "Switch statement" b
switch ${1:expression}${1/(.+)/ /}{
case${0}
}
endsnippet
snippet select "Select statement" b
select {
case${0}
}
endsnippet
snippet case "Case clause" b
case ${1:condition}:
${0:${VISUAL}}
endsnippet
snippet default "Default clause" b
default:
${0:${VISUAL}}
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
snippet anon "Anonymous Function" !b
${1:fn} := func() {
${2}
}
endsnippet
# types and variables
snippet map "Map type" b
map[${1:keytype}]${2:valtype}
endsnippet
snippet : "Short variable declaration :=" !b
${1:name} := ${0:value}
endsnippet
snippet var "Variable declaration" b
var ${1:name}${2/(.+)/ /}${2:type}${3: = ${0:value}}
endsnippet
snippet vars "Variables declaration" b
var (
${1:name}${2/(.+)/ /}${2:type}${3: = ${0:value} }
)
endsnippet
snippet json "JSON field"
\`json:"${1:displayName}"\`
endsnippet
snippet er "Error clause " !b
if err != nil {
# if condition
snippet if "if ... { ... }"
if ${1:condition} {
${0}
}
endsnippet
# else snippet
snippet else
else {
${0}
}
endsnippet
# error snippet
snippet errn "Error return " !b
if err != nil {
return err
@ -161,55 +153,195 @@ if err != nil {
${0}
endsnippet
snippet errn,, "Error return with three return values" !b
if err != nil {
return ${1:nil}, ${2:nil}, err
}
${0}
snippet json "\`json:key\`"
\`json:"${1:keyName}"\`
endsnippet
snippet ok "OK statement" !b
if !ok {
# fallthrough
snippet ft "fallthrough"
fallthrough
endsnippet
# for loop
snippet for "for ... { ... }"
for ${1} {
${0}
}
endsnippet
# for integer loop
snippet fori "for 0..N-1 { ... }"
for ${1:i} := 0; $1 < ${2:N}; $1++ {
${0}
}
endsnippet
# for range loop
snippet forr "for k, v := range items { ... }"
for ${2:k}, ${3:v} := range ${1} {
${0}
}
endsnippet
# function
snippet func "func Function(...) [error] { ... }"
func ${1:name}(${2:params})${3/(.+)/ /}`!p opening_par(snip, 3)`$3`!p closing_par(snip, 3)` {
${0:${VISUAL}}
}
endsnippet
snippet gof "Anonymous Goroutine" !b
# Fmt Printf debug
snippet ff "fmt.Printf(...)"
fmt.Printf("${1} = %+v\n", $1)
endsnippet
# Fmt Println debug
snippet fn "fmt.Println(...)"
fmt.Println("${1}")
endsnippet
# log printf
snippet lf "log.Printf(...)"
log.Printf("${1} = %+v\n", $1)
endsnippet
# log println
snippet ln "log.Println(...)"
log.Println("${1}")
endsnippet
# make
snippet make "make(Type, size)"
make(${1:[]string}, ${2:0})${0}
endsnippet
# map
snippet map "map[Type]Type"
map[${1:string}]${0:int}
endsnippet
# main()
snippet main "func main() { ... }"
func main() {
${0}
}
endsnippet
# method
snippet meth "func (self Type) Method(...) [error] { ... }"
func (${1:receiver} ${2:type}) ${3:name}(${4:params})${5/(.+)/ /}`!p opening_par(snip, 5)`$5`!p closing_par(snip, 5)` {
${0:${VISUAL}}
}
endsnippet
# ok
snippet ok "if !ok { ... }"
if !ok {
${0}
}
endsnippet
# package
snippet package "package ..."
// Package $1 provides ${2:...}
package ${1:main}
${0}
endsnippet
# panic
snippet pn "panic()"
panic("${0:msg}")
endsnippet
# return
snippet rt "return"
return ${0}
endsnippet
# select
snippet select "select { case a := <-chan: ... }"
select {
case ${1:v1} := <-${2:chan1}
${0}
}
endsnippet
# struct
snippet st "type T struct { ... }"
type ${1:Type} struct {
${0}
}
endsnippet
# switch
snippet switch "switch x { ... }"
switch ${1:var} {
case ${2:value1}:
${0}
}
endsnippet
# sprintf
snippet sp "fmt.Sprintf(...)"
fmt.Sprintf("%${1:s}", ${2:var})
endsnippet
# goroutine named function
snippet go "go someFunc(...)"
go ${1:funcName}(${0})
endsnippet
# goroutine anonymous function
snippet gof "go func() { ... }()"
go func() {
${1}
}()
endsnippet
snippet def "Anonymous Defer" !b
defer func() {
${1}
}()
endsnippet
snippet ff "Fmt Printf debug" !b
fmt.Printf("${1} %+v\n", $1)
endsnippet
snippet fn "Fmt Println debug" !b
fmt.Println("${1}")
endsnippet
snippet lf "Log Printf debug" !b
log.Printf("${1} %+v\n", $1)
endsnippet
snippet ln "Log Println debug" !b
log.Println("${1}")
endsnippet
snippet make "make allocation" !b
make(${1:Type}, ${2:size})${0}
endsnippet
snippet test "test function" b
# test function
snippet test "func TestXYZ(t *testing.T) { ... }"
func Test${1:Function}(t *testing.T) {
${2}
${0}
}
endsnippet
# variable declaration
snippet var "var x Type [= ...]"
var ${1:x} ${2:Type}${3: = ${0:value\}}
endsnippet
# variables declaration
snippet vars "var ( ... )"
var (
${1:x} ${2:Type}${3: = ${0:value\}}
)
endsnippet
global !p
import re
# Automatically wrap return types with parentheses
def return_values(s):
# remove everything wrapped in parentheses
s = re.sub("\(.*?\)|\([^)]*$", "", s)
return len(s.split(","))
def opening_par(snip, pos):
if return_values(t[pos]) > 1 and not t[pos].startswith("("):
snip.rv = "("
else:
snip.rv = ""
def closing_par(snip, pos):
if return_values(t[pos]) > 1:
snip.rv = ")"
else:
snip.rv = ""
endglobal
# vim:ft=snippets:

View File

@ -1,53 +1,70 @@
# 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}
)
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})
# bool
snippet bl
bool
# byte
snippet bt
byte
# break
snippet br
abbr break
break
# channel
snippet ch
abbr chan Type
chan ${0:int}
# case
snippet cs
snippet case
abbr case ...:
case ${1:value}:
${0}
# const
snippet c
const ${1:NAME} = ${0:0}
# constants with iota
snippet co
# constant
snippet con
abbr const XXX Type = ...
const ${1:NAME} ${2:Type} = ${0:0}
# constants
snippet cons
abbr const ( ... )
const (
${1:NAME1} = iota
${0:NAME2}
${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
defer ${0:func}()
abbr defer someFunction()
defer ${1:func}(${2})
${0}
snippet def
abbr defer func() { ... }
defer func() {
${0}
}()
# defer recover
snippet dfr
snippet defr
defer func() {
if err := recover(); err != nil {
${0}
@ -73,171 +90,185 @@ snippet gpl
*/
${0}
# int
snippet i
int
# import
snippet im
snippet import
abbr import ( ... )
import (
"${1:package}"
)
# interface
snippet in
interface{}
# full interface snippet
snippet inf
interface ${1:name} {
${2:/* methods */}
snippet interface
abbr interface I { ... }
type ${1:Interface} interface {
${2:/* TODO: add methods */}
}
# if condition
snippet if
if ${1:/* condition */} {
${2}
abbr if ... { ... }
if ${1:condition} {
${0}
}
# else snippet
snippet el
abbr else { ... }
snippet else
else {
${1}
${0}
}
# error snippet
snippet ir
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}
# false
snippet f
false
# json snippet
snippet json
abbr \`json:key\`
\`json:"${1:keyName}"\`
# fallthrough
snippet ft
abbr fallthrough
fallthrough
# float
snippet fl
float32
# float32
snippet f3
float32
# float64
snippet f6
float64
# if else
snippet ie
if ${1:/* condition */} {
${2}
} else {
${3}
}
${0}
# for loop
snippet fo
for ${2:i} := 0; $2 < ${1:count}; $2${3:++} {
${4}
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}
}
${0}
# for range loop
snippet fr
for ${1:k}, ${2:v} := range ${3} {
${4}
snippet forr
abbr for k, v := range items { ... }
for ${2:k}, ${3:v} := range ${1} {
${0}
}
${0}
# function simple
snippet fun
func ${1:funcName}(${2}) ${3:error} {
${4}
# function
snippet func
abbr func function(...) [error] { ... }
func ${1:function}(${2}) ${3:error }{
${0}
}
${0}
# function on receiver
snippet fum
func (self ${1:type}) ${2:funcName}(${3}) ${4:error} {
${5}
}
${0}
# Fmt Printf debug
snippet ff
fmt.Printf("${1} %+v\n", ${0})
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
log.Printf("%${1:s}", ${2:var})
# log printf
snippet lp
abbr log.Printf(...)
log.Printf("${1} = %+v\n", $1)
# log println
snippet ln
abbr log.Println(...)
log.Println("${1}")
# make
snippet mk
make(${1:[]string}, ${0:0})
snippet make
abbr make(Type, size)
make(${1:[]string}, ${2:0})${0}
# map
snippet mp
snippet map
abbr map[Type]Type
map[${1:string}]${0:int}
# main()
snippet main
abbr func main() { ... }
options head
func main() {
${1}
${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}
# new
snippet nw
new(${0:type})
# panic
snippet pn
panic("${0:msg}")
# print
snippet pr
fmt.Printf("%${1:s}\n", ${2:var})
# range
snippet rn
range ${0}
snippet panic
alias pn
abbr panic("...")
panic("${0}")
# return
snippet rt
snippet return
alias rt
abbr return ...
return ${0}
# result
snippet rs
result
# select
snippet sl
snippet select
abbr select { case a := <-chan: ... }
select {
case ${1:v1} := <-${2:chan1}
${3}
case ${4:v2} := <-${5:chan2}
${6}
default:
${0}
}
# string
snippet sr
string
# struct
snippet st
struct ${1:name} {
${2:/* data */}
}
${0}
# switch
snippet sw
switch ${1:var} {
case ${2:value1}:
${3}
case ${4:value2}:
${5}
default:
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})
# true
snippet t
true
# goroutine named function
snippet g
snippet go
abbr go someFunc(...)
go ${1:funcName}(${0})
# goroutine anonymous function
snippet ga
go func(${1} ${2:type}) {
${3:/* code */}
}(${0})
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) {
${2}
${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\}}
)