Recently, we are preparing to migrate the go development environment to Linux. Because xshell SSH is used to connect to Ubuntu server, sublime cannot be used, anyway, VIM was quite familiar with it before, and it was simply transferred to VIM for development.
Linux go installation is very convenient. Download the official package and decompress it directlyhome
Directory, and then configure the environment variables. I use Ubuntu server. If you add the following content to the. profile file in the home directory
Export goroot = $ home/go # location of the go language installation package
export PATH=$PATH:$GOROOT/bin
Export gopath = $ home/mygo # Put your own code under mygo
export PATH=$PATH:$GOPATH/bin
The Vim plug-in is managed using vundle, which is backed up on GitHub. Here we mainly add the auto-completion plug-in for the go language under vim.
Use the go command line toolgocode
Install
go get github.com/nsf/gocode
Add the corresponding Vim plug-in.
Bundle ‘dgryski/vim-godef‘
?
Finally, configuregocode
Tools
gocode set propose-builtins true
Rungocode set
Command to view the return value
By default, gocode only searches
$GOPATH/pkg/$GOOS_$GOARCH````$GOROOT/pkg/$GOOS_$GOARCH
The packages under these two directories can be called if there are other places to search
gocode set lib-path path
To add.
After the above plug-in is installed, edit the go file in VIM to highlight it. If you need to complete it automatically, pressCtrl+x Ctrl + o
The Completion list is displayed.
To view the function definition and struct definition of the current file, you can usegotags
Cooperationtagbar
Plugin implementation
Install gotags
go get github.com/jstemmer/gotags
Add the tagbar configuration in vimrc
let g:tagbar_type_go = {
\ ‘ctagstype‘ : ‘go‘,
\ ‘kinds‘ : [
\ ‘p:package‘,
\ ‘i:imports:1‘,
\ ‘c:constants‘,
\ ‘v:variables‘,
\ ‘t:types‘,
\ ‘n:interfaces‘,
\ ‘w:fields‘,
\ ‘e:embedded‘,
\ ‘m:methods‘,
\ ‘r:constructor‘,
\ ‘f:functions‘
\ ],
\ ‘sro‘ : ‘.‘,
\ ‘kind2scope‘ : {
\ ‘t‘ : ‘ctype‘,
\ ‘n‘ : ‘ntype‘
\ },
\ ‘scope2kind‘ : {
\ ‘ctype‘ : ‘t‘,
\ ‘ntype‘ : ‘n‘
\ },
\ ‘ctagsbin‘ : ‘gotags‘,
\ ‘ctagsargs‘ : ‘-sort -silent‘
\ }
From Weizhi note (wiz)
Configure the go development environment of VIM