Go language installation and vim-go configuration __go

Source: Internet
Author: User
Tags sleep function git clone gocode
Go language installation and vim-go configuration

Mild obsessive-compulsive disorder ...

Recently void-001 in writing Neuoj_judge back-end evaluation machine, and I am also relatively idle recently, so I want to follow VOID-001, looking at his code, go to study. Go installation If you are more confident of your own ladder can be downloaded on the official website to the compiler, if not confident, you can use the domestic Golang China http://www.golangtc.com/download (Don't worry about the version behind, Version is synchronized), download go1.7.3.linux-amd64.tar.gz

After the download, the first decompression, and then you can put the extracted files in their favorite location. After the configuration:

Export Goroot=/your path/go1.7.3.linux-amd64/go   //Download installation package after decompression location
export path= $PATH: $GOROOT/bin    // Download the installation package after extracting the location/bin, which is the executable file
export gopath=/like path/go  //Your favorite Go language workspace workspace, set yourself
To this end, the installation is complete. Use Go version to verify that the installation was successful. use of Go development environmentMany people ask what development environment the Go language uses, personally think it is better to use VIM, in fact, the current mainstream go development environment has not a mainstream IDE, are required to do on the other IDE on the going plug-in configuration, rather than in a hundreds of trillion environment development, rather than using VIM

Vim configuration, Vim-go is currently the most widely used to build the Golang development environment of the VIM plug-in, so we use the Vim-go plug-in. Vim-go is installed using the Open-source Vim plugin manager, and Gmarik/vundle.vim is currently the recommended number of Vim plugin managers. can refer to the official introduction Https://github.com/VundleVim/Vundle.vim download. git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/vundle.vim configuration. At the beginning of the ~.VIMRC, configure the following (paste the past directly),

    "-------------" Vundle "Https://github.com/gmarik/Vundle.vim"-------------set nocompatible "is improved, required filetype off" required "set the runtime path to include Vundl E and initialize set Rtp+=~/.vim/bundle/vundle.vim call Vundle#begin () "Alternatively, pass a path where vund Le should install plugins "Call Vundle#begin (' ~/some/path/here ')"-let Vundle manage vundle, required Plugin  
  ' Gmarik/vundle.vim ' "The following are examples of different formats.  
  "Keep Plugin commands between vundle#begin/end. "Plugin on GitHub repo" "Plugin ' tpope/vim-fugitive '" plugin from http://vim-scripts.org/vim/scripts.html "" Plugin ' L9 ' "Git Plugin not hosted on GitHub" "Plugin ' git://git.wincent.com/command-t.git '" "Git Repos on yo ur local machine (i.e. when working on your own plugin) "Plugin ' File:///home/gmarik/path/to/plugin '" "Sparku P VIm script is in a subdirectory the this repo called Vim.  
  "Pass's path to set the Runtimepath properly."   

  "" Plugin ' Rstacruz/sparkup ', {' RTP ': ' vim/'} "avoid a name conflict with L9" "Plugin ' user/l9 ', {' name ': ' NewL9 '} "Install vim-go Plugin ' fatih/vim-go '" All of your Plugins-must to added before the following line CA ll Vundle#end () "Required filetype plugin indent on ' required ' to ignore plugin indent, I Nstead use: ' FileType plugin on ' Brief help ":P luginlist-lists configured plugins":P Lugi Ninstall-installs plugins; Append '! ' to update or just:P luginupdate ':P luginsearch foo-searches for foo; Append '! ' to refresh the local cache ':P luginclean-confirms removal of unused plugins; Append '! ' to Auto-approve removal ' "see:h vundle for more details or wikis for FAQs" Put your Non-plugin St   Uff
Use the Plugininstall command in vim for vim-go installation, note: In the previous configuration, I have been added to the Vim-go plugin. Once the installation is complete, you can have the word Fugauliang display for the go language.

In order to realize the automatic complement congruent function, also needs to carry on the goinstallbinaries installation. Use the command goinstallbinaries in vim. will automatically install some binary executable files, such as Gocode, Godef, Goimports and so on, is installed under $gopath/bin, can be the LS for command viewing. But this method is generally not good, because code.google.com by the wall, causing some hosted on the code.google.com on the top of the bag go do not come down. But don't worry about it, programmers have super powers. The following is resolved. First of all, find the files we need to install, ~/.vim/bundle/vim-go/plugin/go.vim in this file, Luo lists the commands that need to be installed, actually very small, each only dozens of KB. Enumerate the key contents of this file.

    "These packages are used by vim-go and can are automatically installed if  
" needed by the user with goinstallbinaries< C2/>let s:packages = ["  
            github.com/nsf/gocode",   
            \ "Code.google.com/p/go.tools/cmd/goimports",   
            \ " Code.google.com/p/rog-go/exp/cmd/godef ",   
            \" Code.google.com/p/go.tools/cmd/oracle ",   
            \" code.google.com/p /go.tools/cmd/gorename ",  
            \" Github.com/golang/lint/golint ",   
            \" Github.com/kisielk/errcheck ",  
            \" Github.com/jstemmer/gotags ",  
            \]  
Next, we need a file to download a file. Here it is still in Golang China, Http://www.golangtc.com/download/package, this page tells the detailed method of downloading installation, and very simple, do not explain

Install the previous step of those files, basically finished the vim-go configuration, test

Edit Hello.go:
-A new line of input FMT, and then Ctrl+x, Ctrl+o,vim will pop up the Fill prompt dropdown box, but not immediately follow the kind of completion, which is provided by the Gocode.
– Enter a line of code: time. Sleep (time. Second), execution: Goimports,vim will automatically import the time package.
– Move the cursor over the sleep function, and execute: typing gd,vim in godef or command mode opens the definition of the sleep function in $goroot/src/time/sleep.go. Execution: B 1 return to Hellogolang.go.
– Execute: Golint, run Golint on the current go source file.
– Execute: Godoc to open the go document for the current cursor's corresponding symbol.
– Execute: Govet, run the Go vet in the current directory on the current move source file.
– Execute: Gorun, compile to run the current main package.
– Execute: gobuild, compile the current package, depending on your source file, Gobuild does not produce a result file.
– Execute: Goinstall, install the current package.
– Execute: gotest, test your current path _test.go file.
– Execute: gocoverage, create a test overlay result file, and open the browser to show the current package.
– Execute: Goerrcheck to check for possible errors that are not captured by the current package.
– Execute: gofiles, showing the list of source files for the current package.
– Execute: godeps, displaying the list of dependent packages for the current package.
– Execute: goimplements to display a list of interface for the current type implementation.
– Execute: gorename [to] replaces the symbol under the current cursor with [to].

Real-time following code completion installation YCM (Your Complete Me)

Add a row to the ~/.VIMRC:
Plugin ' Valloric/youcompleteme '
saves the exit, then opens the/ETC/VIMRC and executes the:P Lugininstall.

After that, you need to open the ~/.vim/xxx/ycm./install.sh, which, according to the prompts to install can be installed after the installation is complete, you can be automatically prompted sometimes, you may encounter problems, such as not automatically prompted, the reason is Youcompleteme Unavailable:no module named future. At first I looked for this mistake for a long time and then found the answer in a blog post.

The reason is that you are either not vundle installed, or vundle because the speed is too slow to download to half of the installation dependent package can not be completely downloaded
Solution:
Enter the Youcompleteme directory and terminal git submodule in the Windows update–init–recursive

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.