vim‐go - meetbill/Vim GitHub Wiki
1 安装
https://github.com/fatih/vim-go
2 使用
2.1 版本提示
vim-go requires at least Vim 8.1.2269 or Neovim 0.4.0, but you're using an older version.
Please update your Vim for the best vim-go experience.
If you really want to continue you can set this to make the error go away:
let g:go_version_warning = 0
Note that some features may error out or behave incorrectly.
Please do not report bugs unless you're using at least Vim 8.1.2269 or Neovim 0.4.0.
在 .vimrc 添加
let g:go_version_warning = 0
2.2 函数提示
vim-go: could not find 'gopls'. Run :GoInstallBinaries to fix it
打开vim-go项目目录下的plugin/go.vim可以找到:
" these packages are used by vim-go and can be automatically installed if
" needed by the user with GoInstallBinaries.
let s:packages = {
\ 'asmfmt': ['github.com/klauspost/asmfmt/cmd/asmfmt'],
\ 'dlv': ['github.com/go-delve/delve/cmd/dlv'],
\ 'errcheck': ['github.com/kisielk/errcheck'],
\ 'fillstruct': ['github.com/davidrjenni/reftools/cmd/fillstruct'],
\ 'gocode': ['github.com/mdempsky/gocode', {'windows': ['-ldflags', '-H=windowsgui']}],
\ 'gocode-gomod': ['github.com/stamblerre/gocode'],
\ 'godef': ['github.com/rogpeppe/godef'],
\ 'gogetdoc': ['github.com/zmb3/gogetdoc'],
\ 'goimports': ['golang.org/x/tools/cmd/goimports'],
\ 'golint': ['golang.org/x/lint/golint'],
\ 'gopls': ['golang.org/x/tools/cmd/gopls'],
\ 'gometalinter': ['github.com/alecthomas/gometalinter'],
\ 'golangci-lint': ['github.com/golangci/golangci-lint/cmd/golangci-lint'],
\ 'gomodifytags': ['github.com/fatih/gomodifytags'],
\ 'gorename': ['golang.org/x/tools/cmd/gorename'],
\ 'gotags': ['github.com/jstemmer/gotags'],
\ 'guru': ['golang.org/x/tools/cmd/guru'],
\ 'impl': ['github.com/josharian/impl'],
\ 'keyify': ['honnef.co/go/tools/cmd/keyify'],
\ 'motion': ['github.com/fatih/motion'],
\ 'iferr': ['github.com/koron/iferr'],
\ }
如注释所言,:GoInstallBinaries实际上是把这些二进制文件安装到本地
安装到的目录为 go env
命令中的 $GOPATH/bin
中
- GOROOT:GOROOT就是Go的安装目录,(类似于java的JDK)
- GOPATH:GOPATH是我们的工作空间,保存go项目代码和第三方依赖包
安装之后,会在 $GOPATH/bin
目录下看到如下文件
-rwxrwxr-x 1 work work 2790020 7月 13 16:46 asmfmt
-rwxrwxr-x 1 work work 20479363 7月 13 16:42 dlv
-rwxrwxr-x 1 work work 6743211 7月 13 16:41 errcheck
-rwxrwxr-x 1 work work 6573622 7月 13 16:40 fillstruct
-rwxrwxr-x 1 work work 7961924 7月 13 16:40 godef
-rwxrwxr-x 1 work work 57474288 7月 13 16:44 golangci-lint
-rwxrwxr-x 1 work work 3631869 7月 13 16:45 gomodifytags
-rwxrwxr-x 1 work work 39363164 7月 13 16:39 gopls
-rwxrwxr-x 1 work work 3033492 7月 13 16:43 gotags
-rwxrwxr-x 1 work work 2653183 7月 13 16:43 iferr
-rwxrwxr-x 1 work work 6429856 7月 13 16:44 impl
-rwxrwxr-x 1 work work 3402016 7月 13 16:41 motion
-rwxrwxr-x 1 work work 12725758 7月 13 16:38 revive
-rwxrwxr-x 1 work work 14508202 7月 13 16:45 staticcheck