把vim當作golang的IDE

開始決定丟棄鼠標,因此準備用vim了。git

那麼在vim裏面如何搭建golang環境呢?github

git盛行之下,搭建vim環境是如此簡單。golang

並且vim搭建好了以後,基本上跟IDE沒有差異。vim

高亮、自動補全、自動格式化、查看定義跳轉、語法檢測等等等等, 簡直是不要不要的:oracle

  • 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 or neosnippet
  • 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 or inner 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

 

安裝起來也很是方便,只要一下三行代碼:async

#下載安裝
git clone git@github.com:farazdagi/vim-go-ide.git ~/.vim_go_runtime sh ~/.vim_go_runtime/bin/install #運行 vim -u ~/.vimrc.go

PS:ide

a)這裏要求vim 要開啓lua  :  函數

brew install vim --with-lua --override-system-vim

b)若是須要類解析,須要轉ctagui

 

--------------------lua

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/

效果以下:

相關文章
相關標籤/搜索