開始決定丟棄鼠標,所以准備用vim了。
那么在vim里面如何搭建golang環境呢?
git盛行之下,搭建vim環境是如此簡單。
而且vim搭建好了之后,基本上跟IDE沒有差別。
高亮、自動補全、自動格式化、查看定義跳轉、語法檢測等等等等, 簡直是不要不要的:
- Improved Syntax highlighting with items such as Functions, Operators, Methods.
- Auto completion support via
gocode
- Better
gofmt
on save, which 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
:GoImport
or plug it into autosave - Compile your package with
:GoBuild
, install it with:GoInstall
or test them with:GoTest
(also supports running single tests via:GoTestFunc
) - Quickly execute your current file/files with
:GoRun
- Automatic
GOPATH
detection based on the directory structure (i.e.gb
projects,godep
vendored projects) - Change or display
GOPATH
with:GoPath
- Create a coverage profile and display annotated source code in browser to see which functions are covered with
:GoCoverage
- Call
gometalinter
with:GoMetaLinter
, which invokes all possible linters (golint, vet, errcheck, deadcode, etc..) and shows the warnings/errors - Lint your code with
:GoLint
- Run your code through
:GoVet
to catch static errors - Advanced source analysis tools utilizing oracle, such as
:GoImplements
,:GoCallees
, and:GoReferrers
- Precise type-safe renaming of identifiers with
:GoRename
- List all source files and dependencies
- Unchecked error checking with
:GoErrCheck
- Integrated and improved snippets, supporting
ultisnips
orneosnippet
- Share your current code to play.golang.org with
:GoPlay
- On-the-fly type information about the word under the cursor. Plug it into your custom vim function.
- Go asm formatting on save
- Tagbar support to show tags of the source code in a sidebar with
gotags
- Custom vim text objects such as
a function
orinner function
list. - A async launcher for the go command is implemented for Neovim, fully async building and testing (beta).
- Integrated with the Neovim terminal, launch
:GoRun
and other go commands in their own new terminal. (beta) - Alternate between implementation and test code with
:GoAlternate
安裝起來也非常方便,只要一下三行代碼:
#下載安裝
git clone git@github.com:farazdagi/vim-go-ide.git ~/.vim_go_runtime
sh ~/.vim_go_runtime/bin/install
#運行
vim -u ~/.vimrc.go
PS:
a)這里要求vim 要開啟lua :
brew install vim --with-lua --override-system-vim
b)如果需要類解析,需要轉ctag
--------------------
2016-10-20補充
如果把go升級到go1.7,這里的函數 auto-complete 會顯示PANIC不能顯示任何的系統庫對應的函數和自定義的函數
這里需要做一件事情,可以恢復
ps aux | grep gocode #存在就干掉 killall gocode #重啟 gocode
或者采用以下方式
gocode close && go get -u github.com/nsf/gocode
參考這里:https://github.com/fatih/vim-go/issues/1015
---------------------
原文:http://farazdagi.com/blog/2015/vim-as-golang-ide/
效果如下: