mirror of
https://github.com/amix/vimrc
synced 2025-08-01 18:35:00 +08:00
Updated plugins
This commit is contained in:
@ -33,6 +33,7 @@ disabled/enabled easily.
|
||||
* Share your current code to [play.golang.org](http://play.golang.org)
|
||||
* On-the-fly type information about the word under the cursor
|
||||
* Tagbar support to show tags of the source code in a sidebar with `gotags`
|
||||
* Custom vim text objects, such a `a function` or `inner function`
|
||||
|
||||
## Install
|
||||
|
||||
@ -53,9 +54,10 @@ and execute `:PluginInstall` (or `:BundleInstall` for older versions of Vundle)
|
||||
|
||||
Please be sure all necessary binaries are installed (such as `gocode`, `godef`,
|
||||
`goimports`, etc..). You can easily install them with the included
|
||||
`:GoInstallBinaries`. Those binaries will be automatically downloaded and
|
||||
installed to your `$GOBIN` environment (if not set it will use `$GOPATH/bin`).
|
||||
It requires `git` and `hg` for fetching the individual Go packages.
|
||||
`:GoInstallBinaries` command. Those binaries will be automatically downloaded
|
||||
and installed to your `$GOBIN` environment (if not set it will use
|
||||
`$GOPATH/bin`). It requires `git` and `hg` for fetching the individual Go
|
||||
packages.
|
||||
|
||||
### Optional
|
||||
|
||||
@ -72,13 +74,12 @@ completion (completion by type) install:
|
||||
|
||||
## Usage
|
||||
|
||||
All [features](#features) are enabled by default. There are no additional
|
||||
settings needed. Usage and commands are listed in `doc/vim-go.txt`. Just open
|
||||
the help page to see all commands:
|
||||
Many of the [features](#features) are enabled by default. There are no
|
||||
additional settings needed. All usages and commands are listed in
|
||||
`doc/vim-go.txt`. Just open the help page to see all commands:
|
||||
|
||||
:help vim-go
|
||||
|
||||
|
||||
## Mappings
|
||||
|
||||
vim-go has several `<Plug>` mappings which can be used to create custom
|
||||
@ -178,56 +179,14 @@ let g:go_bin_path = expand("~/.gotools")
|
||||
let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path
|
||||
```
|
||||
|
||||
## Snippets
|
||||
|
||||
Snippets are useful and very powerful. By default ultisnips is
|
||||
used, however you can change it to neosnippet with:
|
||||
|
||||
By default syntax-highlighting for Functions, Methods and Structs is disabled.
|
||||
To change it:
|
||||
```vim
|
||||
let g:go_snippet_engine = "neosnippet"
|
||||
let g:go_highlight_functions = 1
|
||||
let g:go_highlight_methods = 1
|
||||
let g:go_highlight_structs = 1
|
||||
```
|
||||
|
||||
Snippet feature is enabled only if the snippet plugins are installed. Below are
|
||||
some examples snippets and the corresponding trigger keywords, The `|`
|
||||
character defines the cursor. Ultisnips has support for multiple cursors
|
||||
|
||||
|
||||
`ff` is useful for debugging:
|
||||
|
||||
```go
|
||||
fmt.Printf(" | %+v\n", |)
|
||||
```
|
||||
|
||||
`errn` expands to:
|
||||
|
||||
```go
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
```
|
||||
|
||||
Use `gof` to quickly create a anonymous goroutine :
|
||||
|
||||
```go
|
||||
go func() {
|
||||
|
|
||||
}()
|
||||
```
|
||||
|
||||
To add `json` tags to a struct field, use `json` trigger:
|
||||
|
||||
```
|
||||
type foo struct {
|
||||
bar string `json:"myField"
|
||||
^ type `json` here, hit tab and type "myField". It will expand to `json:"myField"`
|
||||
}
|
||||
```
|
||||
|
||||
...
|
||||
|
||||
And many more! For the full list have a look at the
|
||||
[included snippets](https://github.com/fatih/vim-go/blob/master/gosnippets/):
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### I'm using Fish shell but have some problems using Vim-go
|
||||
|
@ -3,9 +3,22 @@ if !exists("g:go_jump_to_error")
|
||||
endif
|
||||
|
||||
function! go#cmd#Run(bang, ...)
|
||||
let goFiles = '"' . join(go#tool#Files(), '" "') . '"'
|
||||
|
||||
if IsWin()
|
||||
exec '!go run ' . goFiles
|
||||
if v:shell_error
|
||||
redraws! | echon "vim-go: [run] " | echohl ErrorMsg | echon "FAILED"| echohl None
|
||||
else
|
||||
redraws! | echon "vim-go: [run] " | echohl Function | echon "SUCCESS"| echohl None
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
let default_makeprg = &makeprg
|
||||
if !len(a:000)
|
||||
let &makeprg = "go run " . join(go#tool#Files(), ' ')
|
||||
let &makeprg = 'go run ' . goFiles
|
||||
else
|
||||
let &makeprg = "go run " . expand(a:1)
|
||||
endif
|
||||
@ -25,8 +38,8 @@ function! go#cmd#Run(bang, ...)
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Install(...)
|
||||
let pkgs = join(a:000, ' ')
|
||||
let command = 'go install '.pkgs
|
||||
let pkgs = join(a:000, '" "')
|
||||
let command = 'go install "' . pkgs . '"'
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
@ -41,13 +54,13 @@ function! go#cmd#Install(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Build(bang)
|
||||
function! go#cmd#Build(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), ' ')
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
if v:shell_error
|
||||
let &makeprg = "go build . errors"
|
||||
else
|
||||
let &makeprg = "go build -o /dev/null " . gofiles
|
||||
let &makeprg = "go build -o /dev/null " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "building ..."| echohl None
|
||||
@ -60,7 +73,7 @@ function! go#cmd#Build(bang)
|
||||
if g:go_jump_to_error
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None
|
||||
endif
|
||||
endif
|
||||
@ -75,21 +88,22 @@ function! go#cmd#Test(...)
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "testing ..." | echohl None
|
||||
redraw
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if g:go_jump_to_error
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
endif
|
||||
echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None
|
||||
else
|
||||
call setqflist([])
|
||||
endif
|
||||
cwindow
|
||||
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if g:go_jump_to_error
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
redraw | echon "vim-go: " | echohl Function | echon "[test] PASS" | echohl None
|
||||
cwindow
|
||||
echon "vim-go: " | echohl Function | echon "[test] PASS" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -43,9 +43,9 @@ fu! s:gocodeCommand(cmd, preargs, args)
|
||||
let a:preargs[i] = s:gocodeShellescape(a:preargs[i])
|
||||
endfor
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_gocode_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
let bin_path = go#tool#BinPath(g:go_gocode_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let result = s:system(printf('%s %s %s %s', bin_path, join(a:preargs), a:cmd, join(a:args)))
|
||||
@ -96,7 +96,7 @@ function! go#complete#GetInfo()
|
||||
|
||||
" no candidates are found
|
||||
if len(out) == 1
|
||||
return
|
||||
return ""
|
||||
endif
|
||||
|
||||
" only one candiate is found
|
||||
@ -119,14 +119,16 @@ function! go#complete#GetInfo()
|
||||
if len(filtered) == 1
|
||||
return filtered[0]
|
||||
endif
|
||||
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
function! go#complete#Info()
|
||||
let result = go#complete#GetInfo()
|
||||
if len(result) > 0
|
||||
if !empty(result)
|
||||
echo "vim-go: " | echohl Function | echon result | echohl None
|
||||
endif
|
||||
endfunction!
|
||||
endfunction
|
||||
|
||||
fu! go#complete#Complete(findstart, base)
|
||||
"findstart = 1 when we need to get the text length
|
||||
|
@ -13,15 +13,15 @@ function! go#def#Jump(...)
|
||||
let arg = a:1
|
||||
endif
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_godef_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
let bin_path = go#tool#BinPath(g:go_godef_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), "\n"))
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), LineEnding()))
|
||||
|
||||
" jump to it
|
||||
call s:godefJump(out, "")
|
||||
@ -31,15 +31,15 @@ endfunction
|
||||
function! go#def#JumpMode(mode)
|
||||
let arg = s:getOffset()
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_godef_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
let bin_path = go#tool#BinPath(g:go_godef_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), "\n"))
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), LineEnding()))
|
||||
|
||||
call s:godefJump(out, a:mode)
|
||||
endfunction
|
||||
@ -51,7 +51,7 @@ function! s:getOffset()
|
||||
let offs = line2byte(pos[0]) + pos[1] - 2
|
||||
else
|
||||
let c = pos[1]
|
||||
let buf = line('.') == 1 ? "" : (join(getline(1, pos[0] - 1), "\n") . "\n")
|
||||
let buf = line('.') == 1 ? "" : (join(getline(1, pos[0] - 1), LineEnding()) . LineEnding())
|
||||
let buf .= c == 1 ? "" : getline(pos[0])[:c-2]
|
||||
let offs = len(iconv(buf, &encoding, "utf-8"))
|
||||
endif
|
||||
@ -66,7 +66,7 @@ function! s:godefJump(out, mode)
|
||||
let &errorformat = "%f:%l:%c"
|
||||
|
||||
if a:out =~ 'godef: '
|
||||
let out=substitute(a:out, '\n$', '', '')
|
||||
let out=substitute(a:out, LineEnding() . '$', '', '')
|
||||
echom out
|
||||
else
|
||||
let parts = split(a:out, ':')
|
||||
@ -85,7 +85,7 @@ function! s:godefJump(out, mode)
|
||||
let &switchbuf = "usetab"
|
||||
|
||||
if bufloaded(fileName) == 0
|
||||
tab split
|
||||
tab split
|
||||
endif
|
||||
else
|
||||
if a:mode == "split"
|
||||
@ -96,11 +96,10 @@ function! s:godefJump(out, mode)
|
||||
endif
|
||||
|
||||
" jump to file now
|
||||
ll 1
|
||||
sil ll 1
|
||||
normal zz
|
||||
|
||||
let &switchbuf = old_switchbuf
|
||||
end
|
||||
let &errorformat = old_errorformat
|
||||
endfunction
|
||||
|
||||
|
@ -35,7 +35,7 @@ function! s:godocWord(args)
|
||||
if !executable('godoc')
|
||||
echohl WarningMsg
|
||||
echo "godoc command not found."
|
||||
echo " install with: go get code.google.com/p/go.tools/cmd/godoc"
|
||||
echo " install with: go get golang.org/x/tools/cmd/godoc"
|
||||
echohl None
|
||||
return []
|
||||
endif
|
||||
@ -51,7 +51,7 @@ function! s:godocWord(args)
|
||||
let words = a:args
|
||||
endif
|
||||
|
||||
if !len(words)
|
||||
if !len(words)
|
||||
return []
|
||||
endif
|
||||
|
||||
@ -85,7 +85,7 @@ function! go#doc#OpenBrowser(...)
|
||||
call go#tool#OpenBrowser(godoc_url)
|
||||
endfunction
|
||||
|
||||
function! go#doc#Open(mode, ...)
|
||||
function! go#doc#Open(newmode, mode, ...)
|
||||
let pkgs = s:godocWord(a:000)
|
||||
if empty(pkgs)
|
||||
return
|
||||
@ -102,10 +102,14 @@ function! go#doc#Open(mode, ...)
|
||||
return -1
|
||||
endif
|
||||
|
||||
call s:GodocView(a:mode, content)
|
||||
call s:GodocView(a:newmode, a:mode, content)
|
||||
|
||||
if exported_name == ''
|
||||
silent! normal gg
|
||||
return -1
|
||||
endif
|
||||
|
||||
" jump to the specified name
|
||||
|
||||
if search('^func ' . exported_name . '(')
|
||||
silent! normal zt
|
||||
return -1
|
||||
@ -125,11 +129,11 @@ function! go#doc#Open(mode, ...)
|
||||
silent! normal gg
|
||||
endfunction
|
||||
|
||||
function! s:GodocView(position, content)
|
||||
function! s:GodocView(newposition, position, content)
|
||||
" reuse existing buffer window if it exists otherwise create a new one
|
||||
if !bufexists(s:buf_nr)
|
||||
execute a:position
|
||||
file `="[Godoc]"`
|
||||
execute a:newposition
|
||||
sil file `="[Godoc]"`
|
||||
let s:buf_nr = bufnr('%')
|
||||
elseif bufwinnr(s:buf_nr) == -1
|
||||
execute a:position
|
||||
@ -149,9 +153,9 @@ function! s:GodocView(position, content)
|
||||
setlocal iskeyword-=-
|
||||
|
||||
setlocal modifiable
|
||||
%delete _
|
||||
%delete _
|
||||
call append(0, split(a:content, "\n"))
|
||||
$delete _
|
||||
sil $delete _
|
||||
setlocal nomodifiable
|
||||
endfunction
|
||||
|
||||
|
@ -2,13 +2,19 @@ if !exists("g:go_errcheck_bin")
|
||||
let g:go_errcheck_bin = "errcheck"
|
||||
endif
|
||||
|
||||
function! go#errcheck#Run() abort
|
||||
let bin_path = go#tool#BinPath(g:go_errcheck_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
function! go#errcheck#Run(...) abort
|
||||
if a:0 == 0
|
||||
let package = go#package#ImportPath(expand('%:p:h'))
|
||||
else
|
||||
let package = a:1
|
||||
end
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_errcheck_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let out = system(bin_path . ' ' . shellescape(expand('%:p:h')))
|
||||
let out = system(bin_path . ' ' . package)
|
||||
if v:shell_error
|
||||
let errors = []
|
||||
let mx = '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)'
|
||||
@ -16,7 +22,7 @@ function! go#errcheck#Run() abort
|
||||
let tokens = matchlist(line, mx)
|
||||
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": tokens[1],
|
||||
call add(errors, {"filename": expand(DefaultGoPath() . "/src/" . tokens[1]),
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4]})
|
||||
|
@ -39,6 +39,10 @@ if !exists('g:go_fmt_options')
|
||||
let g:go_fmt_options = ''
|
||||
endif
|
||||
|
||||
if !exists("g:go_fmt_experimental")
|
||||
let g:go_fmt_experimental = 0
|
||||
endif
|
||||
|
||||
let s:got_fmt_error = 0
|
||||
|
||||
" we have those problems :
|
||||
@ -57,12 +61,15 @@ function! go#fmt#Format(withGoimport)
|
||||
let l:tmpname=tempname()
|
||||
call writefile(getline(1,'$'), l:tmpname)
|
||||
|
||||
" save our undo file to be restored after we are done. This is needed to
|
||||
" prevent an additional undo jump due to BufWritePre auto command and also
|
||||
" restore 'redo' history because it's getting being destroyed every
|
||||
" BufWritePre
|
||||
let tmpundofile=tempname()
|
||||
exe 'wundo! ' . tmpundofile
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" save our undo file to be restored after we are done. This is needed to
|
||||
" prevent an additional undo jump due to BufWritePre auto command and also
|
||||
" restore 'redo' history because it's getting being destroyed every
|
||||
" BufWritePre
|
||||
let tmpundofile=tempname()
|
||||
exe 'wundo! ' . Tmpundofile
|
||||
endif
|
||||
|
||||
" get the command first so we can test it
|
||||
let fmt_command = g:go_fmt_command
|
||||
@ -128,9 +135,11 @@ function! go#fmt#Format(withGoimport)
|
||||
cwindow
|
||||
endif
|
||||
|
||||
" restore our undo history
|
||||
silent! exe 'rundo ' . tmpundofile
|
||||
call delete(tmpundofile)
|
||||
if g:go_fmt_experimental == 1
|
||||
" restore our undo history
|
||||
silent! exe 'rundo ' . tmpundofile
|
||||
call delete(tmpundofile)
|
||||
endif
|
||||
|
||||
" restore our cursor/windows positions
|
||||
call delete(l:tmpname)
|
||||
|
@ -3,8 +3,7 @@
|
||||
"
|
||||
" Part of this plugin was taken directly from the oracle repo, however it's
|
||||
" massively changed for a better integration into vim-go. Thanks Alan Donovan
|
||||
" for the first iteration based on quickfix! - fatih arslan
|
||||
"
|
||||
" for the first iteration based on quickfix! - Fatih Arslan
|
||||
"
|
||||
|
||||
if !exists("g:go_oracle_bin")
|
||||
@ -89,8 +88,6 @@ func! s:RunOracle(mode, selected) range abort
|
||||
" unfortunaly oracle outputs a very long stack trace that is not
|
||||
" parsable to show the real error. But the main issue is usually the
|
||||
" package which doesn't build.
|
||||
" echo out
|
||||
" redraw | echon 'vim-go: could not run static analyser (does it build?)'
|
||||
redraw | echon "vim-go: " | echohl Statement | echon out | echohl None
|
||||
return {}
|
||||
else
|
||||
@ -139,12 +136,12 @@ function! go#oracle#Implements(selected)
|
||||
endfor
|
||||
|
||||
" open a window and put the result
|
||||
call go#ui#OpenWindow(result)
|
||||
call go#ui#OpenWindow("Implements", result)
|
||||
|
||||
" define some buffer related mappings:
|
||||
"
|
||||
" go to definition when hit enter
|
||||
nnoremap <buffer> <CR> :<C-u>call go#ui#OpenDefinition()<CR>
|
||||
nnoremap <buffer> <CR> :<C-u>call go#ui#OpenDefinition("implements")<CR>
|
||||
" close the window when hit ctrl-c
|
||||
nnoremap <buffer> <c-c> :<C-u>call go#ui#CloseWindow()<CR>
|
||||
endfunction
|
||||
@ -182,7 +179,43 @@ endfunction
|
||||
" Show possible targets of selected function call
|
||||
function! go#oracle#Callees(selected)
|
||||
let out = s:RunOracle('callees', a:selected)
|
||||
echo out
|
||||
if empty(out)
|
||||
return
|
||||
endif
|
||||
|
||||
" be sure the callees object exists which contains the position and names
|
||||
" of the callees, before we continue
|
||||
if !has_key(out, "callees")
|
||||
return
|
||||
endif
|
||||
|
||||
" get the callees list
|
||||
if has_key(out.callees, "callees")
|
||||
let callees = out.callees.callees
|
||||
else
|
||||
redraw | echon "vim-go: " | echon "no callees available"| echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let title = "Call targets:"
|
||||
|
||||
" start to populate our buffer content
|
||||
let result = [title, ""]
|
||||
|
||||
for calls in callees
|
||||
let line = calls.name . "\t" . calls.pos
|
||||
call add(result, line)
|
||||
endfor
|
||||
|
||||
" open a window and put the result
|
||||
call go#ui#OpenWindow("Callees", result)
|
||||
|
||||
" define some buffer related mappings:
|
||||
"
|
||||
" go to definition when hit enter
|
||||
nnoremap <buffer> <CR> :<C-u>call go#ui#OpenDefinition("call targets")<CR>
|
||||
" close the window when hit ctrl-c
|
||||
nnoremap <buffer> <c-c> :<C-u>call go#ui#CloseWindow()<CR>
|
||||
endfunction
|
||||
|
||||
" Show possible callers of selected function
|
||||
|
@ -19,9 +19,9 @@ function! go#rename#Rename(...)
|
||||
return
|
||||
endif
|
||||
|
||||
let fname = expand('%:p:t')
|
||||
let fname = resolve(expand('%:p:t'))
|
||||
let pos = s:getpos(line('.'), col('.'))
|
||||
let cmd = printf('%s -offset %s:#%d -to %s', bin_path, shellescape(fname), pos, to)
|
||||
let cmd = printf('%s -offset %s -to %s', shellescape(bin_path), shellescape(printf('%s:#%d', fname, pos)), shellescape(to))
|
||||
|
||||
let out = go#tool#ExecuteInDir(cmd)
|
||||
|
||||
|
15
sources_non_forked/vim-go/autoload/go/textobj.vim
Normal file
15
sources_non_forked/vim-go/autoload/go/textobj.vim
Normal file
@ -0,0 +1,15 @@
|
||||
if !exists("g:go_textobj_enabled")
|
||||
let g:go_textobj_enabled = 1
|
||||
endif
|
||||
|
||||
function! go#textobj#Function(mode)
|
||||
if search('^\s*func .*{$', 'Wce', line('.')) <= 0
|
||||
\ && search('^\s*func .*{$', 'bWce') <= 0
|
||||
return
|
||||
endif
|
||||
if a:mode == 'a'
|
||||
normal! Va{V
|
||||
else " a:mode == 'i'
|
||||
normal! Vi{V
|
||||
endif
|
||||
endfunction
|
@ -1,18 +1,15 @@
|
||||
function! go#tool#Files()
|
||||
if has ("win32")
|
||||
let command = 'go list -f "{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{printf \"\n\"}}{{end}}"'
|
||||
if IsWin()
|
||||
let command = 'go list -f "{{range $f := .GoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}"'
|
||||
else
|
||||
" let command = "go list -f $'{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}\n{{end}}'"
|
||||
|
||||
let command = "go list -f '{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}'"
|
||||
|
||||
let command = "go list -f '{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}'"
|
||||
endif
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
return split(out, '\n')
|
||||
endfunction
|
||||
|
||||
function! go#tool#Deps()
|
||||
if has ("win32")
|
||||
if IsWin()
|
||||
let command = 'go list -f "{{range $f := .Deps}}{{$f}}{{printf \"\n\"}}{{end}}"'
|
||||
else
|
||||
let command = "go list -f $'{{range $f := .Deps}}{{$f}}\n{{end}}'"
|
||||
@ -23,7 +20,7 @@ endfunction
|
||||
|
||||
function! go#tool#Imports()
|
||||
let imports = {}
|
||||
if has ("win32")
|
||||
if IsWin()
|
||||
let command = 'go list -f "{{range $f := .Imports}}{{$f}}{{printf \"\n\"}}{{end}}"'
|
||||
else
|
||||
let command = "go list -f $'{{range $f := .Imports}}{{$f}}\n{{end}}'"
|
||||
@ -35,7 +32,7 @@ function! go#tool#Imports()
|
||||
endif
|
||||
|
||||
for package_path in split(out, '\n')
|
||||
let package_name = fnamemodify(package_path, ":t")
|
||||
let package_name = fnamemodify(package_path, ":t:r")
|
||||
let imports[package_name] = package_path
|
||||
endfor
|
||||
|
||||
@ -45,8 +42,12 @@ endfunction
|
||||
function! go#tool#ShowErrors(out)
|
||||
let errors = []
|
||||
for line in split(a:out, '\n')
|
||||
let fatalerrors = matchlist(line, '^\(fatal error:.*\)$')
|
||||
let tokens = matchlist(line, '^\s*\(.\{-}\):\(\d\+\):\s*\(.*\)')
|
||||
if !empty(tokens)
|
||||
|
||||
if !empty(fatalerrors)
|
||||
call add(errors, {"text": fatalerrors[1]})
|
||||
elseif !empty(tokens)
|
||||
call add(errors, {"filename" : expand("%:p:h:") . "/" . tokens[1],
|
||||
\"lnum": tokens[2],
|
||||
\"text": tokens[3]})
|
||||
@ -120,7 +121,7 @@ function! go#tool#BinPath(binpath)
|
||||
" append our GOBIN and GOPATH paths and be sure they can be found there...
|
||||
" let us search in our GOBIN and GOPATH paths
|
||||
let old_path = $PATH
|
||||
let $PATH = $PATH . ":" .go_bin_path
|
||||
let $PATH = $PATH . PathSep() .go_bin_path
|
||||
|
||||
if !executable(binpath)
|
||||
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
|
||||
@ -140,7 +141,7 @@ endfunction
|
||||
function! s:get_browser_command()
|
||||
let go_play_browser_command = get(g:, 'go_play_browser_command', '')
|
||||
if go_play_browser_command == ''
|
||||
if has('win32') || has('win64')
|
||||
if IsWin()
|
||||
let go_play_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%'
|
||||
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
|
||||
let go_play_browser_command = 'open %URL%'
|
||||
|
@ -1,11 +1,11 @@
|
||||
let s:buf_nr = -1
|
||||
|
||||
"OpenWindow opens a new scratch window and put's the content into the window
|
||||
function! go#ui#OpenWindow(content)
|
||||
function! go#ui#OpenWindow(title, content)
|
||||
" reuse existing buffer window if it exists otherwise create a new one
|
||||
if !bufexists(s:buf_nr)
|
||||
execute 'botright new'
|
||||
file `="[Implements]"`
|
||||
file `="[" . a:title . "]"`
|
||||
let s:buf_nr = bufnr('%')
|
||||
elseif bufwinnr(s:buf_nr) == -1
|
||||
execute 'botright new'
|
||||
@ -17,9 +17,9 @@ function! go#ui#OpenWindow(content)
|
||||
|
||||
" Keep minimum height to 10, if there is more just increase it that it
|
||||
" occupies all results
|
||||
let implements_height = 10
|
||||
if len(a:content) < implements_height
|
||||
exe 'resize ' . implements_height
|
||||
let buffer_height = 10
|
||||
if len(a:content) < buffer_height
|
||||
exe 'resize ' . buffer_height
|
||||
else
|
||||
exe 'resize ' . len(a:content)
|
||||
endif
|
||||
@ -58,11 +58,11 @@ endfunction
|
||||
|
||||
" OpenDefinition parses the current line and jumps to it by openening a new
|
||||
" tab
|
||||
function! go#ui#OpenDefinition()
|
||||
function! go#ui#OpenDefinition(filter)
|
||||
let curline = getline('.')
|
||||
|
||||
" don't touch our first line and any blank line
|
||||
if curline =~ "implements" || curline =~ "^$"
|
||||
" don't touch our first line or any blank line
|
||||
if curline =~ a:filter || curline =~ "^$"
|
||||
" supress information about calling this function
|
||||
echo ""
|
||||
return
|
||||
|
@ -15,8 +15,12 @@ endif
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo-=C
|
||||
if filereadable("makefile") || filereadable("Makefile")
|
||||
CompilerSet makeprg=make
|
||||
else
|
||||
CompilerSet makeprg=go\ build
|
||||
endif
|
||||
|
||||
CompilerSet makeprg=go\ build
|
||||
CompilerSet errorformat=
|
||||
\%-G#\ %.%#,
|
||||
\%-G%.%#panic:\ %m,
|
||||
|
@ -17,10 +17,11 @@ CONTENTS *go-contents*
|
||||
1. Intro........................................|go-intro|
|
||||
2. Install......................................|go-install|
|
||||
3. Commands.....................................|go-commands|
|
||||
4. Settings.....................................|go-settings|
|
||||
5. Mappings.....................................|go-mappings|
|
||||
6. Troubleshooting..............................|go-troubleshooting|
|
||||
7. Credits......................................|go-credits|
|
||||
4. Mappings.....................................|go-mappings|
|
||||
5. Text Objects.................................|go-text-objects|
|
||||
6. Settings.....................................|go-settings|
|
||||
7. Troubleshooting..............................|go-troubleshooting|
|
||||
8. Credits......................................|go-credits|
|
||||
|
||||
===============================================================================
|
||||
INTRO *go-intro*
|
||||
@ -49,7 +50,7 @@ easily.
|
||||
* Checking with `errcheck` for unchecked errors.
|
||||
* Integrated and improved snippets. Supports `ultisnips` or `neosnippet`
|
||||
* Share your current code to play.golang.org
|
||||
* Type information about the underlying identifier
|
||||
* Type information about the underlying identifier
|
||||
* Tagbar support to show tags of the source code in a sidebar with `gotags`
|
||||
|
||||
===============================================================================
|
||||
@ -134,7 +135,7 @@ COMMANDS *go-commands*
|
||||
|
||||
Filter the current Go buffer through goimports (needs to be installed).
|
||||
`goimports` automatically discards/add import path based on the code. Like
|
||||
|GoFmt|, It tries to preserve cursor position and avoids replacing the
|
||||
|GoFmt|, It tries to preserve cursor position and avoids replacing the
|
||||
buffer with stderr output.
|
||||
|
||||
*:GoPlay*
|
||||
@ -159,7 +160,7 @@ COMMANDS *go-commands*
|
||||
|
||||
Goto declaration/definition for the given [identifier]. If no argument is
|
||||
given, it will jump to the declaration under the cursor. By default the
|
||||
mapping `gd` is enabled to invoke GoDef for the identifier under the cursor.
|
||||
mapping `gd` is enabled to invoke GoDef for the identifier under the cursor.
|
||||
See |g:go_def_mapping_enabled| to disable it.
|
||||
|
||||
*:GoRun*
|
||||
@ -167,16 +168,19 @@ COMMANDS *go-commands*
|
||||
|
||||
Build and run your current main package. By default all main files for the
|
||||
current file is used. If an argument is passed, 'expand' is used as file
|
||||
selector. For example use `:GoRun %` to select the current file only.
|
||||
selector. For example use `:GoRun %` to select the current file only.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoBuild*
|
||||
:GoBuild[!]
|
||||
:GoBuild[!] [options]
|
||||
|
||||
Build your package with `go build`. It automatically builds only the files
|
||||
that depends on the current file. GoBuild doesn't produce a result file.
|
||||
Use 'make' to create a result file.
|
||||
Use 'make' to create a result file.
|
||||
|
||||
You may optionally pass any valid go build flags/options. For a full list
|
||||
please see `go help build`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
@ -238,8 +242,9 @@ COMMANDS *go-commands*
|
||||
:GoImplements
|
||||
|
||||
Show 'implements' relation for a selected package. A list of interfaces
|
||||
for the type under the cursor (or selected package) is shown in a custom
|
||||
window. Hit `<enter>` to jump in a new tab or close it via `<c-c>`.
|
||||
for the type that implements an interface under the cursor (or selected
|
||||
package) is shown in a custom window. Hit `<enter>` to jump in a new tab
|
||||
or close it via `<c-c>`.
|
||||
|
||||
*:GoRename*
|
||||
:GoRename [to]
|
||||
@ -247,6 +252,16 @@ COMMANDS *go-commands*
|
||||
Rename the identifier under the cursor to the desired new name. If no
|
||||
argument is given a prompt will ask for the desired identifier.
|
||||
|
||||
*:GoCallees*
|
||||
:GoCallees
|
||||
|
||||
Show 'callees' relation for a selected package. A list of call targets
|
||||
for the type under the cursor (or selected package) is shown in a custom
|
||||
window. Hit `<enter>` to jump in a new tab or close it via `<c-c>`. For
|
||||
example if called for a interface method call, it will show all call targets
|
||||
that has implemented the method.
|
||||
|
||||
|
||||
===============================================================================
|
||||
MAPPINGS *go-mappings*
|
||||
|
||||
@ -353,6 +368,23 @@ Show the interfaces that the type under the cursor implements.
|
||||
|
||||
Rename the identifier under the cursor to the desired new name
|
||||
|
||||
*(go-callees)*
|
||||
|
||||
Show the call targets for the type under the cursor
|
||||
|
||||
===============================================================================
|
||||
TEXT OBJECTS *go-text-objects*
|
||||
|
||||
vim-go comes with several custom |text-objects| that can be used to operate
|
||||
upon regions of text. vim-go currently defines the following text objects:
|
||||
|
||||
*go-v_af* *go-af*
|
||||
af "a function", select contents from a function definition to the
|
||||
closing bracket.
|
||||
|
||||
*go-v_if* *go-if*
|
||||
if "inside a function", select contents of a function,
|
||||
excluding the function definition and the closing bracket.
|
||||
|
||||
|
||||
===============================================================================
|
||||
@ -410,6 +442,16 @@ fails. By default it's disabled. >
|
||||
|
||||
let g:go_fmt_fail_silently = 0
|
||||
<
|
||||
|
||||
*'g:go_fmt_experimental'*
|
||||
|
||||
Use this option to enable fmt's experimental mode. This experimental mode is
|
||||
superior to the current mode as it fully saves the undo history, so undo/redo
|
||||
doesn't break. However it's causing problems on some Vim versions. By default
|
||||
it's disabled. >
|
||||
|
||||
let g:go_fmt_experimental = 1
|
||||
<
|
||||
*'g:go_doc_keywordprg_enabled'*
|
||||
|
||||
Use this option to change the enable GoDoc to run on words under the cursor
|
||||
@ -443,7 +485,7 @@ is empty. >
|
||||
|
||||
< *'g:go_bin_path'*
|
||||
|
||||
Use this option to change default path for vim-go tools when using
|
||||
Use this option to change default path for vim-go tools when using
|
||||
|GoInstallBinaries| and |GoUpdateBinaries|. If not set `$GOBIN` or
|
||||
`$GOPATH/bin` is used. >
|
||||
|
||||
@ -517,6 +559,12 @@ Highlights struct names. By default it's disabled. >
|
||||
|
||||
let g:go_highlight_structs = 0
|
||||
<
|
||||
*'g:go_textobj_enabled'*
|
||||
|
||||
Adds custom text objects. By default it's enabled. >
|
||||
|
||||
let g:go_textobj_enabled = 1
|
||||
|
||||
===============================================================================
|
||||
TROUBLESHOOTING *go-troubleshooting*
|
||||
|
||||
|
@ -9,9 +9,7 @@ if exists("b:did_ftplugin")
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
if !exists("g:go_auto_type_info")
|
||||
let g:go_auto_type_info = 0
|
||||
endif
|
||||
let b:undo_ftplugin = "setl fo< com< cms<"
|
||||
|
||||
setlocal formatoptions-=t
|
||||
|
||||
@ -22,42 +20,27 @@ setlocal noexpandtab
|
||||
|
||||
compiler go
|
||||
|
||||
if !exists("g:go_doc_keywordprg_enabled")
|
||||
let g:go_doc_keywordprg_enabled = 1
|
||||
endif
|
||||
if g:go_doc_keywordprg_enabled
|
||||
" keywordprg doesn't allow to use vim commands, override it
|
||||
nnoremap <buffer> <silent> K :GoDoc<cr>
|
||||
endif
|
||||
|
||||
|
||||
if !exists("g:go_def_mapping_enabled")
|
||||
let g:go_def_mapping_enabled = 1
|
||||
endif
|
||||
if g:go_def_mapping_enabled
|
||||
nnoremap <buffer> <silent> gd :GoDef<cr>
|
||||
endif
|
||||
|
||||
|
||||
let b:undo_ftplugin = "setl fo< com< cms<"
|
||||
|
||||
" Set gocode completion
|
||||
setlocal omnifunc=go#complete#Complete
|
||||
|
||||
" GoInfo automatic update
|
||||
if g:go_auto_type_info != 0
|
||||
setlocal updatetime=300
|
||||
au! CursorHold *.go nested call go#complete#Info()
|
||||
if get(g:, "go_doc_keywordprg_enabled", 1)
|
||||
" keywordprg doesn't allow to use vim commands, override it
|
||||
nnoremap <buffer> <silent> K :GoDoc<cr>
|
||||
endif
|
||||
|
||||
|
||||
" autoload settings
|
||||
if !exists('g:go_fmt_autosave')
|
||||
let g:go_fmt_autosave = 1
|
||||
if get(g:, "go_def_mapping_enabled", 1)
|
||||
nnoremap <buffer> <silent> gd :GoDef<cr>
|
||||
endif
|
||||
|
||||
if g:go_fmt_autosave
|
||||
autocmd BufWritePre <buffer> call go#fmt#Format(-1)
|
||||
if get(g:, "go_textobj_enabled", 1)
|
||||
onoremap <buffer> af :<c-u>call go#textobj#Function('a')<cr>
|
||||
xnoremap <buffer> af :<c-u>call go#textobj#Function('a')<cr>
|
||||
onoremap <buffer> if :<c-u>call go#textobj#Function('i')<cr>
|
||||
xnoremap <buffer> if :<c-u>call go#textobj#Function('i')<cr>
|
||||
endif
|
||||
|
||||
if get(g:, "go_auto_type_info", 0)
|
||||
setlocal updatetime=800
|
||||
endif
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
@ -17,6 +17,7 @@ nnoremap <silent> <Plug>(go-info) :<C-u>call go#complete#Info()<CR>
|
||||
nnoremap <silent> <Plug>(go-import) :<C-u>call go#import#SwitchImport(1, '', expand('<cword>'))<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-implements) :<C-u>call go#oracle#Implements(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callees) :<C-u>call go#oracle#Callees(-1)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-rename) :<C-u>call go#rename#Rename()<CR>
|
||||
|
||||
@ -25,10 +26,10 @@ nnoremap <silent> <Plug>(go-def-vertical) :<C-u>call go#def#JumpMode("vsplit")<C
|
||||
nnoremap <silent> <Plug>(go-def-split) :<C-u>call go#def#JumpMode("split")<CR>
|
||||
nnoremap <silent> <Plug>(go-def-tab) :<C-u>call go#def#JumpMode("tab")<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-doc) :<C-u>call go#doc#Open("leftabove new")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-tab) :<C-u>call go#doc#Open("tabnew")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-vertical) :<C-u>call go#doc#Open("vnew")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-split) :<C-u>call go#doc#Open("split")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc) :<C-u>call go#doc#Open("new", "split")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-tab) :<C-u>call go#doc#Open("tabnew", "tabe")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-vertical) :<C-u>call go#doc#Open("vnew", "vsplit")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-split) :<C-u>call go#doc#Open("new", "split")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-browser) :<C-u>call go#doc#OpenBrowser()<CR>
|
||||
|
||||
|
||||
@ -37,6 +38,7 @@ command! -nargs=? GoRename call go#rename#Rename(<f-args>)
|
||||
|
||||
" oracle
|
||||
command! -range=% GoImplements call go#oracle#Implements(<count>)
|
||||
command! -range=% GoCallees call go#oracle#Callees(<count>)
|
||||
|
||||
" tool
|
||||
command! -nargs=0 GoFiles echo go#tool#Files()
|
||||
@ -45,7 +47,7 @@ command! -nargs=* GoInfo call go#complete#Info()
|
||||
|
||||
" cmd
|
||||
command! -nargs=* -bang GoRun call go#cmd#Run(<bang>0,<f-args>)
|
||||
command! -nargs=? -bang GoBuild call go#cmd#Build(<bang>0)
|
||||
command! -nargs=* -bang GoBuild call go#cmd#Build(<bang>0,<f-args>)
|
||||
command! -nargs=* GoInstall call go#cmd#Install(<f-args>)
|
||||
command! -nargs=* GoTest call go#cmd#Test(<f-args>)
|
||||
command! -nargs=* GoCoverage call go#cmd#Coverage(<f-args>)
|
||||
@ -58,7 +60,7 @@ command! -nargs=0 -range=% GoPlay call go#play#Share(<count>, <line1>, <line2>)
|
||||
command! -nargs=* -range GoDef :call go#def#Jump(<f-args>)
|
||||
|
||||
" -- doc
|
||||
command! -nargs=* -range -complete=customlist,go#package#Complete GoDoc call go#doc#Open('leftabove new', <f-args>)
|
||||
command! -nargs=* -range -complete=customlist,go#package#Complete GoDoc call go#doc#Open('new', 'split', <f-args>)
|
||||
command! -nargs=* -range -complete=customlist,go#package#Complete GoDocBrowser call go#doc#OpenBrowser(<f-args>)
|
||||
|
||||
" -- fmt
|
||||
@ -74,12 +76,11 @@ command! -nargs=* -complete=customlist,go#package#Complete GoImportAs call go#im
|
||||
command! GoLint call go#lint#Run()
|
||||
|
||||
" -- errcheck
|
||||
command! GoErrCheck call go#errcheck#Run()
|
||||
command! -nargs=? -complete=customlist,go#package#Complete GoErrCheck call go#errcheck#Run(<f-args>)
|
||||
|
||||
" Disable all commands until they are fully integrated.
|
||||
"
|
||||
" command! -range=% GoOracleDescribe call go#oracle#Describe(<count>)
|
||||
" command! -range=% GoOracleCallees call go#oracle#Callees(<count>)
|
||||
" command! -range=% GoOracleCallers call go#oracle#Callers(<count>)
|
||||
" command! -range=% GoOracleCallgraph call go#oracle#Callgraph(<count>)
|
||||
" command! -range=% GoOracleCallstack call go#oracle#Callstack(<count>)
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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\}}
|
||||
)
|
||||
|
@ -7,12 +7,12 @@ let g:go_loaded_install = 1
|
||||
" these packages are used by vim-go and can be automatically installed if
|
||||
" needed by the user with GoInstallBinaries
|
||||
let s:packages = [
|
||||
\ "github.com/nsf/gocode",
|
||||
\ "code.google.com/p/go.tools/cmd/goimports",
|
||||
\ "code.google.com/p/rog-go/exp/cmd/godef",
|
||||
\ "code.google.com/p/go.tools/cmd/oracle",
|
||||
\ "code.google.com/p/go.tools/cmd/gorename",
|
||||
\ "github.com/golang/lint/golint",
|
||||
\ "github.com/nsf/gocode",
|
||||
\ "golang.org/x/tools/cmd/goimports",
|
||||
\ "code.google.com/p/rog-go/exp/cmd/godef",
|
||||
\ "golang.org/x/tools/cmd/oracle",
|
||||
\ "golang.org/x/tools/cmd/gorename",
|
||||
\ "github.com/golang/lint/golint",
|
||||
\ "github.com/kisielk/errcheck",
|
||||
\ "github.com/jstemmer/gotags",
|
||||
\ ]
|
||||
@ -23,6 +23,49 @@ command! GoErrCheck call go#errcheck#Run()
|
||||
command! GoInstallBinaries call s:GoInstallBinaries(-1)
|
||||
command! GoUpdateBinaries call s:GoInstallBinaries(1)
|
||||
|
||||
" LineEnding returns the correct line ending, based on the current fileformat
|
||||
function! LineEnding()
|
||||
if &fileformat == 'dos'
|
||||
return "\r\n"
|
||||
elseif &fileformat == 'mac'
|
||||
return "\r"
|
||||
endif
|
||||
|
||||
return "\n"
|
||||
endfunction
|
||||
|
||||
" IsWin returns 1 if current OS is Windows or 0 otherwise
|
||||
function! IsWin()
|
||||
let win = ['win16', 'win32', 'win32unix', 'win64', 'win95']
|
||||
for w in win
|
||||
if (has(w))
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" PathSep returns the appropriate path separator based on OS.
|
||||
function! PathSep()
|
||||
if IsWin()
|
||||
return ";"
|
||||
endif
|
||||
|
||||
return ":"
|
||||
endfunction
|
||||
|
||||
" DefaultGoPath returns the default GOPATH.
|
||||
" If there is only one GOPATH it returns that, otherwise it returns the first one.
|
||||
function! DefaultGoPath()
|
||||
let go_paths = split($GOPATH, PathSep())
|
||||
|
||||
if len(go_paths) == 1
|
||||
return $GOPATH
|
||||
endif
|
||||
|
||||
return go_paths[0]
|
||||
endfunction
|
||||
|
||||
" GetBinPath returns the binary path of installed go tools
|
||||
function! GetBinPath()
|
||||
@ -35,24 +78,11 @@ function! GetBinPath()
|
||||
elseif $GOBIN != ""
|
||||
let bin_path = $GOBIN
|
||||
elseif $GOPATH != ""
|
||||
" take care of multi element GOPATH's
|
||||
let go_paths = split($GOPATH, ":")
|
||||
|
||||
if len(go_paths) == 1
|
||||
" one single PATH
|
||||
let bin_path = $GOPATH . '/bin/'
|
||||
else
|
||||
" multiple paths, use the first one
|
||||
let bin_path = go_paths[0]. '/bin/'
|
||||
endif
|
||||
let bin_path = expand(DefaultGoPath() . "/bin/")
|
||||
else
|
||||
" could not find anything
|
||||
return ""
|
||||
endif
|
||||
|
||||
" add trailing slash if there is no one
|
||||
if bin_path[-1:-1] != '/' | let bin_path .= '/' | endif
|
||||
|
||||
return bin_path
|
||||
endfunction
|
||||
|
||||
@ -60,9 +90,9 @@ endfunction
|
||||
" packages variable. It uses by default $GOBIN or $GOPATH/bin as the binary
|
||||
" target install directory. GoInstallBinaries doesn't install binaries if they
|
||||
" exist, to update current binaries pass 1 to the argument.
|
||||
function! s:GoInstallBinaries(updateBinaries)
|
||||
function! s:GoInstallBinaries(updateBinaries)
|
||||
if $GOPATH == ""
|
||||
echohl Error
|
||||
echohl Error
|
||||
echomsg "vim.go: $GOPATH is not set"
|
||||
echohl None
|
||||
return
|
||||
@ -82,7 +112,17 @@ function! s:GoInstallBinaries(updateBinaries)
|
||||
let old_path = $PATH
|
||||
|
||||
" vim's executable path is looking in PATH so add our go_bin path to it
|
||||
let $PATH = $PATH . ":" .go_bin_path
|
||||
let $PATH = $PATH . PathSep() .go_bin_path
|
||||
|
||||
" when shellslash is set on MS-* systems, shellescape puts single quotes
|
||||
" around the output string. cmd on Windows does not handle single quotes
|
||||
" correctly. Unsetting shellslash forces shellescape to use double quotes
|
||||
" instead.
|
||||
let resetshellslash = 0
|
||||
if has('win32') && &shellslash
|
||||
let resetshellslash = 1
|
||||
set noshellslash
|
||||
endif
|
||||
|
||||
for pkg in s:packages
|
||||
let basename = fnamemodify(pkg, ":t")
|
||||
@ -94,7 +134,7 @@ function! s:GoInstallBinaries(updateBinaries)
|
||||
endif
|
||||
|
||||
if !executable(bin) || a:updateBinaries == 1
|
||||
if a:updateBinaries == 1
|
||||
if a:updateBinaries == 1
|
||||
echo "vim-go: Updating ". basename .". Reinstalling ". pkg . " to folder " . go_bin_path
|
||||
else
|
||||
echo "vim-go: ". basename ." not found. Installing ". pkg . " to folder " . go_bin_path
|
||||
@ -109,6 +149,9 @@ function! s:GoInstallBinaries(updateBinaries)
|
||||
|
||||
" restore back!
|
||||
let $PATH = old_path
|
||||
if resetshellslash
|
||||
set shellslash
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" CheckBinaries checks if the necessary binaries to install the Go tool
|
||||
@ -130,5 +173,23 @@ function! s:CheckBinaries()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Autocommands
|
||||
" ============================================================================
|
||||
|
||||
augroup vim-go
|
||||
autocmd!
|
||||
|
||||
" GoInfo automatic update
|
||||
if get(g:, "go_auto_type_info", 0)
|
||||
autocmd CursorHold *.go nested call go#complete#Info()
|
||||
endif
|
||||
|
||||
" code formatting on save
|
||||
if get(g:, "go_fmt_autosave", 1)
|
||||
autocmd BufWritePre *.go call go#fmt#Format(-1)
|
||||
endif
|
||||
|
||||
augroup END
|
||||
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
@ -10,7 +10,9 @@
|
||||
" let OPTION_NAME = 0
|
||||
" in your ~/.vimrc file to disable particular options. You can also write:
|
||||
" let OPTION_NAME = 1
|
||||
" to enable particular options. At present, all options default to on.
|
||||
" to enable particular options.
|
||||
" At present, all options default to on, except highlight of:
|
||||
" functions, methods and structs.
|
||||
"
|
||||
" - go_highlight_array_whitespace_error
|
||||
" Highlights white space after "[]".
|
||||
@ -107,10 +109,10 @@ syn match goDeclaration /\<func\>/
|
||||
" Predefined functions and values
|
||||
syn keyword goBuiltins append cap close complex copy delete imag len
|
||||
syn keyword goBuiltins make new panic print println real recover
|
||||
syn keyword goConstants iota true false nil
|
||||
syn keyword goBoolean iota true false nil
|
||||
|
||||
hi def link goBuiltins Keyword
|
||||
hi def link goConstants Keyword
|
||||
hi def link goBoolean Boolean
|
||||
|
||||
" Comments; their contents
|
||||
syn keyword goTodo contained TODO FIXME XXX BUG
|
||||
@ -141,9 +143,11 @@ hi def link goEscapeError Error
|
||||
syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
|
||||
syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
|
||||
syn region goRawString start=+`+ end=+`+
|
||||
syn match goFormatSpecifier /%[#0\-\ \+\*]*[vTtbcdoqxXUeEfgGsp]/ contained containedin=goString
|
||||
|
||||
hi def link goString String
|
||||
hi def link goRawString String
|
||||
hi def link goFormatSpecifier goSpecialString
|
||||
|
||||
" Characters; their contents
|
||||
syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU
|
||||
@ -199,7 +203,7 @@ endif
|
||||
" Extra types commonly seen
|
||||
if g:go_highlight_extra_types != 0
|
||||
syn match goExtraType /\<bytes\.\(Buffer\)\>/
|
||||
syn match goExtraType /\<io\.\(Reader\|Writer\|ReadWriter\|ReadWriteCloser\)\>/
|
||||
syn match goExtraType /\<io\.\(Reader\|ReadSeeker\|ReadWriter\|ReadCloser\|ReadWriteCloser\|Writer\|WriteCloser\|Seeker\)\>/
|
||||
syn match goExtraType /\<reflect\.\(Kind\|Type\|Value\)\>/
|
||||
syn match goExtraType /\<unsafe\.Pointer\>/
|
||||
endif
|
||||
|
Reference in New Issue
Block a user