Linux下golang开发环境搭建

对于golang开发来说,Windows下可以用vscode或者liteide都不错,但是Linux下的开发也就只有vim了,所以怎么搞笑的利用vim进行golang开发呢?

参考官方推荐的一个插件:vim-go

安装步骤:

vim-go的安装需要使用vim插件管理工具,我使用的是VundleVim,具体的安装操作按照该工具的readme来操作即可。

当vim-go安装完成之后,按照vim-go的readme里面的介绍,需要用到命令:GoInstallBinaries来安装需要用的工具,但是这里需要说一下,国内因为墙的原因会导致安装失败,这里我的解决办法是找到执行GoInstallBinaries命令时需要安装的工具及其路径,在 ~/.vim/bundle/vim-go/plugin/go.vim 中有如下几行:

 1  'asmfmt':        ['github.com/klauspost/asmfmt/cmd/asmfmt'],
 2  'errcheck':      ['github.com/kisielk/errcheck'],
 3  'fillstruct':    ['github.com/davidrjenni/reftools/cmd/fillstruct'],
 4  'gocode':        ['github.com/nsf/gocode', {'windows': '-ldflags -H=windowsgui'}],
 5  'godef':         ['github.com/rogpeppe/godef'],
 6  'gogetdoc':      ['github.com/zmb3/gogetdoc'],
 7  'goimports':     ['golang.org/x/tools/cmd/goimports'],
 8  'golint':        ['github.com/golang/lint/golint'],
 9  'gometalinter':  ['github.com/alecthomas/gometalinter'],
10  'gomodifytags':  ['github.com/fatih/gomodifytags'],
11  'gorename':      ['golang.org/x/tools/cmd/gorename'],
12  'gotags':        ['github.com/jstemmer/gotags'],
13  'guru':          ['golang.org/x/tools/cmd/guru'],
14  'impl':          ['github.com/josharian/impl'],
15  'keyify':        ['github.com/dominikh/go-tools/cmd/keyify'],
16  'motion':        ['github.com/fatih/motion'],

这里就需要我们自己手动安装了,对于github.com的就执行:go get 路径,对于golang.org的就执行:go install 路径。

在安装golang.org的之前我们需要手动把golang.org的tools工具库(这个是github上的一个镜像)clone到本地。

1、在gopath/src目录下新建golang.org/x目录并cd进去

2、然后git clone https://github.com/golang/tools.git

这样操作之后,就可以进行工具的安装了。

原文地址:https://www.cnblogs.com/lit10050528/p/8151703.html