当前位置: 首页 > 工具软件 > vim-go > 使用案例 >

vim-go安装及配置

唐宇定
2023-12-01

vim-go
使用Vundle.vim安装,在.vimrc相应位置添加如下一句:

Plugin 'fatih/vim-go'

然后:PluginInstall,这样就装好了。

vim-go提供了很多功能,不如称它为一个“collection”,下面装“collection”里面的东西::GoInstallBinaries
如果你没有问题地畅通无阻地看到了“Finished”,除非你不在大陆,要么就是“身在曹营”,IP不知道跑哪去了【你懂的】。

一下操作是针对没有“梯子”的朋友们:
:GoInstallBinaries总共会安装这么几样东西,可以在.vim/bundle/vim-go/plugin/go.vim中看到:

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'],
      \ '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'],
\ }

其中,只要是和golang.org有关系的,你都会安装不成功。甚至gocode等你也不能成功安装,因为依赖golang.org/x/tools中的东西。应对这种情况,Google当然不会放弃广大的中国大陆程序员啦,在github.com/golang里就能找到mirror

  1. $GOPATH/src/建立路径golang.org/x/
cd $GOPATH/src
mkdir -p golang.org/x
cd golang.org/x
  1. toolsclone到当前路径:
git clone https://github.com/golang/tools.git
  1. buildinstall需要的包,以goimports为例(gurugoplsgorename同):
cd tools/cmd/goimports
go buiild
go install
  1. golint的mirror,安装方法同上。
  2. keyify的mirror,需要在src/建立honnef.co/go/,然后clone,并且要该名字,改为tools
  3. 其他的就用:GoInstallBinaries装吧。
 类似资料: