mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
@ -88,7 +88,7 @@ vim-go has several `<Plug>` mappings which can be used to create custom
|
||||
mappings. Below are some examples you might find useful:
|
||||
|
||||
Show a list of interfaces which is implemented by the type under your cursor
|
||||
with `<leader>s`
|
||||
with `<leader>s`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>s <Plug>(go-implements)
|
||||
@ -187,6 +187,8 @@ To change it:
|
||||
let g:go_highlight_functions = 1
|
||||
let g:go_highlight_methods = 1
|
||||
let g:go_highlight_structs = 1
|
||||
let g:go_highlight_operators = 1
|
||||
let g:go_highlight_build_constraints = 1
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
@ -198,13 +200,13 @@ If trying to use `:GoDef`, `:GoInfo` and get a `command not found`, check that
|
||||
Before opening vim, check your current `$PATH`:
|
||||
|
||||
echo $PATH
|
||||
|
||||
after opening vim, run `:echo $PATH`, the output must be your current `$PATH` + `$PATH/bin` (the location where `:GoInstallBinaries` installed the binaries
|
||||
|
||||
after opening vim, run `:echo $PATH`, the output must be your current `$PATH` + `$GOPATH/bin` (the location where `:GoInstallBinaries` installed the binaries
|
||||
|
||||
If problem persists and you are using maybe 'csh' or other shell, try adding this to your .vimrc:
|
||||
|
||||
set shell=/bin/sh
|
||||
|
||||
|
||||
|
||||
|
||||
### I'm using Fish shell but have some problems using Vim-go
|
||||
@ -240,7 +242,7 @@ Give it a try. I hope you like it. Feel free to contribute to the project.
|
||||
|
||||
## Donations
|
||||
|
||||
Vim-go is an open source project and I'm working on it on my free times. I'm spending a lot of time and thoughts to make it stable, fixing bugs, adding new features, etc... If you like vim-go and find it helpful, you might give me a gift from some of the books (kindle) I have in my wish list:
|
||||
Vim-go is an open source project and I'm working on it on my free times. I'm spending a lot of time and thoughts to make it stable, fixing bugs, adding new features, etc... If you like vim-go and find it helpful, you might give me a gift from some of the books (kindle) I have in my wish list:
|
||||
|
||||
[Amazon.com Fatih's Wish List](http://amzn.com/w/3RUTKZC0U30P6). Thanks!
|
||||
|
||||
|
@ -81,13 +81,25 @@ function! go#cmd#Build(bang, ...)
|
||||
let &makeprg = default_makeprg
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Test(...)
|
||||
let command = "go test ."
|
||||
if len(a:000)
|
||||
let command = "go test " . expand(a:1)
|
||||
function! go#cmd#Test(compile, ...)
|
||||
let command = "go test "
|
||||
|
||||
" don't run the test, only compile it. Useful to capture and fix errors or
|
||||
" to create a test binary.
|
||||
if a:compile
|
||||
let command .= "-c"
|
||||
endif
|
||||
|
||||
if len(a:000)
|
||||
let command .= expand(a:1)
|
||||
endif
|
||||
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Identifier | echon "compiling tests ..." | echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Identifier | echon "testing ..." | echohl None
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "testing ..." | echohl None
|
||||
redraw
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
@ -103,7 +115,12 @@ function! go#cmd#Test(...)
|
||||
else
|
||||
call setqflist([])
|
||||
cwindow
|
||||
echon "vim-go: " | echohl Function | echon "[test] PASS" | echohl None
|
||||
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "[test] PASS" | echohl None
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -135,6 +135,11 @@ function! go#complete#Info()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:trim_bracket(val)
|
||||
let a:val.word = substitute(a:val.word, '[(){}\[\]]\+$', '', '')
|
||||
return a:val
|
||||
endfunction
|
||||
|
||||
fu! go#complete#Complete(findstart, base)
|
||||
"findstart = 1 when we need to get the text length
|
||||
if a:findstart == 1
|
||||
@ -142,6 +147,10 @@ fu! go#complete#Complete(findstart, base)
|
||||
return col('.') - g:gocomplete_completions[0] - 1
|
||||
"findstart = 0 when we need to return the list of completions
|
||||
else
|
||||
let s = getline(".")[col('.') - 1]
|
||||
if s =~ '[(){}\{\}]'
|
||||
return map(copy(g:gocomplete_completions[1]), 's:trim_bracket(v:val)')
|
||||
endif
|
||||
return g:gocomplete_completions[1]
|
||||
endif
|
||||
endf
|
||||
|
@ -56,7 +56,7 @@ func! s:qflistSecond(output)
|
||||
" We discard line2 and col2 for the first errorformat, because it's not
|
||||
" useful and quickfix only has the ability to show one line and column
|
||||
" number
|
||||
let &errorformat = "%f:%l.%c-%.%#:\ %m,%f:%l:%c:\ %m"
|
||||
let &errorformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
|
||||
" create the quickfix list and open it
|
||||
cgetexpr split(a:output, "\n")
|
||||
@ -189,6 +189,27 @@ endfunction
|
||||
" Show all refs to entity denoted by selected identifier
|
||||
function! go#oracle#Referrers(selected)
|
||||
let out = s:RunOracle('referrers', a:selected)
|
||||
|
||||
" append line contents from Go source file for some messages:
|
||||
" '...: referenced here'
|
||||
" '...: reference to NAME'
|
||||
let lines = split(out, "\n")
|
||||
let extlines = []
|
||||
for line in lines
|
||||
if line =~# '\v: referenced here$|: reference to [^ :]*$'
|
||||
let parts = split(line, ':')
|
||||
" Note: we count -3 from end, to support additional comma in
|
||||
" Windows-style C:\... paths
|
||||
let filename = join(parts[0:-3], ':')
|
||||
let linenum = parts[-2]
|
||||
let extline = line . ': ' . readfile(filename, '', linenum)[linenum-1]
|
||||
call add(extlines, extline)
|
||||
else
|
||||
call add(extlines, line)
|
||||
endif
|
||||
endfor
|
||||
let out = join(extlines, "\n")
|
||||
|
||||
call s:qflistSecond(out)
|
||||
endfunction
|
||||
|
||||
|
@ -124,17 +124,21 @@ function! go#tool#BinPath(binpath)
|
||||
let old_path = $PATH
|
||||
let $PATH = $PATH . PathSep() .go_bin_path
|
||||
|
||||
if !executable(binpath)
|
||||
if !executable(basename)
|
||||
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
|
||||
" restore back!
|
||||
let $PATH = old_path
|
||||
return ""
|
||||
endif
|
||||
|
||||
" restore back!
|
||||
if go_bin_path
|
||||
let $PATH = old_path
|
||||
let $PATH = old_path
|
||||
|
||||
let sep = '/'
|
||||
if IsWin()
|
||||
let sep = '\'
|
||||
endif
|
||||
|
||||
return go_bin_path . '/' . basename
|
||||
return go_bin_path . sep . basename
|
||||
endfunction
|
||||
|
||||
" following two functions are from: https://github.com/mattn/gist-vim
|
||||
|
@ -38,10 +38,13 @@ easily.
|
||||
* Better `gofmt` on save, keeps cursor position and doesn't break your undo
|
||||
history
|
||||
* Go to symbol/declaration with `godef`
|
||||
* Look up documentation with `godoc` inside Vim or open it in browser.
|
||||
* Automatically import packages via `goimports`
|
||||
* Compile and `go build` your package, install it with `go install`
|
||||
* `go run` quickly your current file/files
|
||||
* Run `go test` and see any errors in quickfix window
|
||||
* Create a coverage profile and display annotated source code in browser to
|
||||
see which functions are covered.
|
||||
* Lint your code with `golint`
|
||||
* Run your code trough `go vet` to catch static errors.
|
||||
* Advanced source analysis tool with `oracle`
|
||||
@ -50,30 +53,49 @@ 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
|
||||
* 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 *go-install*
|
||||
|
||||
If you use pathogen, just clone it into your bundle directory: >
|
||||
Vim-go follows the standard runtime path structure, so I highly recommend to use
|
||||
a common and well known plugin manager to install vim-go. Do not use vim-go with
|
||||
other Go plugins. For Pathogen just clone the repo, for other plugin managers
|
||||
add the appropriate lines and execute the plugin's install command.
|
||||
|
||||
$ cd ~/.vim/bundle
|
||||
$ git clone https://github.com/fatih/vim-go.git
|
||||
* https://github.com/tpope/vim-pathogen >
|
||||
|
||||
git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
|
||||
<
|
||||
|
||||
For Vundle add this line to your vimrc:
|
||||
>
|
||||
Plugin 'fatih/vim-go'
|
||||
* https://github.com/junegunn/vim-plug >
|
||||
|
||||
Plug 'fatih/vim-go'
|
||||
|
||||
<
|
||||
* https://github.com/Shougo/neobundle.vim >
|
||||
|
||||
NeoBundle 'fatih/vim-go'
|
||||
<
|
||||
and execute `:PluginInstall` (or `:BundleInstall` for older versions of Vundle)
|
||||
|
||||
* https://github.com/gmarik/vundle >
|
||||
|
||||
Please be sure all necessary binares are installed (such as `gocode`, `godef`,
|
||||
Plugin 'fatih/vim-go'
|
||||
|
||||
<
|
||||
* Manual >
|
||||
|
||||
Copy all of the files into your `~/.vim` directory
|
||||
<
|
||||
|
||||
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. If you invoke it, all necessary binaries will be
|
||||
automatically downloaded and installed to your `$GOBIN` environment (if not set
|
||||
it will use `$GOPATH/bin`). It requires `git` for fetching the individual Go
|
||||
packages.
|
||||
|
||||
* Autocompletion is enabled by default via `<C-x><C-o>`, to get real-time
|
||||
completion (completion by type) install:
|
||||
@ -199,9 +221,18 @@ COMMANDS *go-commands*
|
||||
*:GoTest*
|
||||
:GoTest [expand]
|
||||
|
||||
Test your _test.go files via in your current directory. Errors are
|
||||
Run the tests on your _test.go files via in your current directory. Errors
|
||||
are populated in quickfix window. If an argument is passed, 'expand' is
|
||||
used as file selector (useful for cases like `:GoTest ./...`).
|
||||
|
||||
*:GoTestCompile*
|
||||
:GoTestCompile [expand]
|
||||
|
||||
Compile your _test.go files via in your current directory. Errors are
|
||||
populated in quickfix window. If an argument is passed, 'expand' is used
|
||||
as file selector (useful for cases like `:GoTest ./...`).
|
||||
as file selector (useful for cases like `:GoTest ./...`). Useful to not
|
||||
run the tests and capture/fix errors before running the tests or to
|
||||
create test binary.
|
||||
|
||||
*:GoCoverage*
|
||||
:GoCoverage
|
||||
@ -359,6 +390,10 @@ Calls `go install` for the current package
|
||||
|
||||
Calls `go test` for the current package
|
||||
|
||||
*(go-test-compile)*
|
||||
|
||||
Calls `go test -c` for the current package
|
||||
|
||||
*(go-coverage)*
|
||||
|
||||
Calls `go test -coverprofile-temp.out` for the current package
|
||||
@ -699,7 +734,8 @@ or
|
||||
set shell='/bin/sh'
|
||||
>
|
||||
|
||||
I'm seeing weirds errors during the startup~
|
||||
I'm seeing weirds errors during installation of binaries with
|
||||
GoInstallBinaries:
|
||||
|
||||
If you see errors like this:
|
||||
>
|
||||
|
@ -8,7 +8,8 @@ let g:go_loaded_commands = 1
|
||||
nnoremap <silent> <Plug>(go-run) :<C-u>call go#cmd#Run(expand('%'))<CR>
|
||||
nnoremap <silent> <Plug>(go-build) :<C-u>call go#cmd#Build('')<CR>
|
||||
nnoremap <silent> <Plug>(go-install) :<C-u>call go#cmd#Install()<CR>
|
||||
nnoremap <silent> <Plug>(go-test) :<C-u>call go#cmd#Test('')<CR>
|
||||
nnoremap <silent> <Plug>(go-test) :<C-u>call go#cmd#Test(0, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-test-compile) :<C-u>call go#cmd#Test(1, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-coverage) :<C-u>call go#cmd#Coverage('')<CR>
|
||||
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#cmd#Vet()<CR>
|
||||
nnoremap <silent> <Plug>(go-files) :<C-u>call go#tool#Files()<CR>
|
||||
@ -63,7 +64,8 @@ command! -nargs=* GoInfo call go#complete#Info()
|
||||
command! -nargs=* -bang GoRun call go#cmd#Run(<bang>0,<f-args>)
|
||||
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=* GoTest call go#cmd#Test(0, <f-args>)
|
||||
command! -nargs=* GoTestCompile call go#cmd#Test(1, <f-args>)
|
||||
command! -nargs=* GoCoverage call go#cmd#Coverage(<f-args>)
|
||||
command! -nargs=0 GoVet call go#cmd#Vet()
|
||||
|
||||
|
@ -38,7 +38,7 @@ endsnippet
|
||||
# case
|
||||
snippet case "case ...:"
|
||||
case ${1:value}:
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
endsnippet
|
||||
|
||||
# constant
|
||||
@ -70,8 +70,7 @@ endsnippet
|
||||
# default case
|
||||
snippet default "default: ..."
|
||||
default:
|
||||
${0}
|
||||
|
||||
${0:${VISUAL}}
|
||||
endsnippet
|
||||
|
||||
# defer
|
||||
@ -82,7 +81,7 @@ endsnippet
|
||||
|
||||
snippet def "defer func() { ... }"
|
||||
defer func() {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}()
|
||||
endsnippet
|
||||
|
||||
@ -90,7 +89,7 @@ endsnippet
|
||||
snippet defr
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
}()
|
||||
endsnippet
|
||||
@ -133,14 +132,14 @@ endsnippet
|
||||
# if condition
|
||||
snippet if "if ... { ... }"
|
||||
if ${1:condition} {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
# else snippet
|
||||
snippet else
|
||||
else {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
@ -167,6 +166,14 @@ if err != nil {
|
||||
${0}
|
||||
endsnippet
|
||||
|
||||
snippet errh "Error handle and return" !b
|
||||
if err != nil {
|
||||
${1}
|
||||
return
|
||||
}
|
||||
${0}
|
||||
endsnippet
|
||||
|
||||
snippet json "\`json:key\`"
|
||||
\`json:"${1:keyName}"\`
|
||||
endsnippet
|
||||
@ -179,21 +186,21 @@ endsnippet
|
||||
# for loop
|
||||
snippet for "for ... { ... }"
|
||||
for ${1} {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
# for integer loop
|
||||
snippet fori "for 0..N-1 { ... }"
|
||||
for ${1:i} := 0; $1 < ${2:N}; $1++ {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
# for range loop
|
||||
snippet forr "for k, v := range items { ... }"
|
||||
for ${2:k}, ${3:v} := range ${1} {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
@ -211,17 +218,17 @@ endsnippet
|
||||
|
||||
# Fmt Println debug
|
||||
snippet fn "fmt.Println(...)"
|
||||
fmt.Println("${1}")
|
||||
fmt.Println("${1:${VISUAL}}")
|
||||
endsnippet
|
||||
|
||||
# log printf
|
||||
snippet lf "log.Printf(...)"
|
||||
log.Printf("${1} = %+v\n", $1)
|
||||
log.Printf("${1:${VISUAL}} = %+v\n", $1)
|
||||
endsnippet
|
||||
|
||||
# log println
|
||||
snippet ln "log.Println(...)"
|
||||
log.Println("${1}")
|
||||
log.Println("${1:${VISUAL}}")
|
||||
endsnippet
|
||||
|
||||
# make
|
||||
@ -237,7 +244,7 @@ endsnippet
|
||||
# main()
|
||||
snippet main "func main() { ... }"
|
||||
func main() {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
@ -251,7 +258,7 @@ endsnippet
|
||||
# ok
|
||||
snippet ok "if !ok { ... }"
|
||||
if !ok {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
@ -269,7 +276,7 @@ endsnippet
|
||||
|
||||
# return
|
||||
snippet rt "return"
|
||||
return ${0}
|
||||
return ${0:${VISUAL}}
|
||||
endsnippet
|
||||
|
||||
# select
|
||||
@ -316,7 +323,7 @@ endsnippet
|
||||
# test function
|
||||
snippet test "func TestXYZ(t *testing.T) { ... }"
|
||||
func Test${1:Function}(t *testing.T) {
|
||||
${0}
|
||||
${0:${VISUAL}}
|
||||
}
|
||||
endsnippet
|
||||
|
||||
@ -346,16 +353,26 @@ endsnippet
|
||||
|
||||
# variable declaration
|
||||
snippet var "var x Type [= ...]"
|
||||
var ${1:x} ${2:Type}${3: = ${0:value\}}
|
||||
var ${1:x} ${2:Type}${3: = ${0:value}}
|
||||
endsnippet
|
||||
|
||||
# variables declaration
|
||||
snippet vars "var ( ... )"
|
||||
var (
|
||||
${1:x} ${2:Type}${3: = ${0:value\}}
|
||||
${1:x} ${2:Type}${3: = ${0:value}}
|
||||
)
|
||||
endsnippet
|
||||
|
||||
# equals fails the test if exp is not equal to act.
|
||||
snippet eq "equals: test two identifiers with DeepEqual"
|
||||
if !reflect.DeepEqual(${1:expected}, ${2:actual}) {
|
||||
_, file, line, _ := runtime.Caller(0)
|
||||
fmt.Printf("%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, $1, $2)
|
||||
t.FailNow()
|
||||
}
|
||||
endsnippet
|
||||
|
||||
|
||||
global !p
|
||||
|
||||
import re
|
||||
|
@ -139,6 +139,16 @@ abbr if err != nil { return [...], err }
|
||||
}
|
||||
${0}
|
||||
|
||||
|
||||
# error snippet handle and return
|
||||
snippet errh
|
||||
abbr if err != nil { return }
|
||||
if err != nil {
|
||||
${1}
|
||||
return
|
||||
}
|
||||
${0}
|
||||
|
||||
# json snippet
|
||||
snippet json
|
||||
abbr \`json:key\`
|
||||
@ -304,3 +314,11 @@ abbr var ( ... )
|
||||
var (
|
||||
${1:x} ${2:Type}${3: = ${0:value\}}
|
||||
)
|
||||
# equals fails the test if exp is not equal to act.
|
||||
snippet eq
|
||||
abbr equals: test two identifiers with DeepEqual
|
||||
if !reflect.DeepEqual(${1:expected}, ${2:actual}) {
|
||||
_, file, line, _ := runtime.Caller(0)
|
||||
fmt.Printf("%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, $1, $2)
|
||||
t.FailNow()
|
||||
}
|
||||
|
Reference in New Issue
Block a user