對於golang開發來說,Windows下可以用vscode或者liteide都不錯,但是Linux下的開發也就只有vim了,所以怎么搞笑的利用vim進行golang開發呢?
安裝步驟:
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
這樣操作之后,就可以進行工具的安裝了。