Configure the go development environment of VIM

Source: Internet
Author: User
Tags gocode gotags

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 directlyhomeDirectory, and then configure the environment variables. I use Ubuntu server. If you add the following content to the. profile file in the home directory

 
 
  1. Export goroot = $ home/go # location of the go language installation package
  2. export PATH=$PATH:$GOROOT/bin 
  3. Export gopath = $ home/mygo # Put your own code under mygo
  4. 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 toolgocodeInstall
go get github.com/nsf/gocode

Add the corresponding Vim plug-in.

 
 
  1. Bundle ‘dgryski/vim-godef‘

?
Finally, configuregocodeTools
gocode set propose-builtins true
Rungocode setCommand 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 pathTo 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 + oThe Completion list is displayed.

To view the function definition and struct definition of the current file, you can usegotagsCooperationtagbarPlugin implementation

Install gotags
go get github.com/jstemmer/gotags

Add the tagbar configuration in vimrc

 
 
  1. let g:tagbar_type_go = {
  2. \ ‘ctagstype‘ : ‘go‘,
  3. \ ‘kinds‘ : [
  4. \ ‘p:package‘,
  5. \ ‘i:imports:1‘,
  6. \ ‘c:constants‘,
  7. \ ‘v:variables‘,
  8. \ ‘t:types‘,
  9. \ ‘n:interfaces‘,
  10. \ ‘w:fields‘,
  11. \ ‘e:embedded‘,
  12. \ ‘m:methods‘,
  13. \ ‘r:constructor‘,
  14. \ ‘f:functions‘
  15. \ ],
  16. \ ‘sro‘ : ‘.‘,
  17. \ ‘kind2scope‘ : {
  18. \ ‘t‘ : ‘ctype‘,
  19. \ ‘n‘ : ‘ntype‘
  20. \ },
  21. \ ‘scope2kind‘ : {
  22. \ ‘ctype‘ : ‘t‘,
  23. \ ‘ntype‘ : ‘n‘
  24. \ },
  25. \ ‘ctagsbin‘ : ‘gotags‘,
  26. \ ‘ctagsargs‘ : ‘-sort -silent‘
  27. \ }


From Weizhi note (wiz)

Configure the go development environment of VIM

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.