This is a creation in Article, where the information may have evolved or changed.
Many editors have been used after contact with Golang, such as Liteidea,sublime2,idea, which I love the most is idea. And then accidentally once used to build a virtual development environment of vagrant and then have to use vim to develop, In order to quickly develop the nature to install a lot of convenient plug-ins. Of course, installing these plugins has to say that I'm sick of it, although some of it is my own. Okay, I'll go first. Let's first look at the image of Vim, the god of the editor.
There is a lot of wood has a pretty cool super-blast day haha start vim plug-in installation bar
First VIM plug-in installation in two forms, has been directly installed in the ~/.vim/plugin directory of the other is to use the plug-In Manager vundle (there are other plugins manager)
Let me introduce you to the type of installation
1 Gmarik/vundle.vim This is the plugin manager.
2 ' valloric/youcompleteme ' Code autocomplete plugin
3 Goimports will automatically delete the imported import package
4 Godef can jump to function definition
5 Gocode This is the Go Code AutoComplete plug-in after the youcompleteme will not need to click CTRL x to appear but when you hit the code automatically appear
6 Gotags This makes it easy for you to see the source code, the right part.
7 Nerdtree This allows you to view the directory structure is also very convenient
~/.VIMRC is a configuration file about vim (if you do not have your own mkdir ~/.VIMRC file in the ~/directory) I will post the article at the end of my. VIMRC Full configuration
Gobin directory Make sure that the correct must be in your PATH environment variable if you set multiple Gopath then you must make sure that you set the Gobin directory to have the executable file to install the plug-in
Vundle installation (Git installs itself on Google)
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/vundle.vim
Adding content to the. VIMRC completes the vundle of the plug-in management part of Vim, which is required to configure the file.
FileType offfiletype plugin indent offset rtp+= $VIM/vimfiles/bundle/vundle/"RC after the parameter means vundle automatically download the location of the installation plug-in, left empty in ~/.vim/ Next Call VUNDLE#RC (' $VIM/vimfiles/bundle/') bundle ' gmarik/vundle ' filetype plugin indent onsyntax on
Goimports Installation
Go get code.google.com/p/go.tools/cmd/goimports
Go Install Code.google.com/p/go.tools/cmd/goimports
There's a goimports on GitHub, but there's a section on this project with moved to the official Go.tools repo so it doesn't apply to GitHub's address.
Add in. vimrc
Bundle ' Cespare/vim-golang '
Let G:gofmt_command = "Goimports"
Autocmd Bufwritepre *.go:fmt
Re-open VIM, Command mode execution: Bunduleinstall
How to use: Enter in command mode: FMT Goimports is automatically invoked in the background, typesetting the currently edited file, and inserting/deleting the corresponding import statement in the file
Godef Installation
Go get code.google.com/p/rog-go/exp/cmd/godef
Go Install Code.google.com/p/rog-go/exp/cmd/godef
Added in. VIMRC
Bundle ' Dgryski/vim-godef '
Re-open VIM, Command mode execution: Bunduleinstall
Use the method to open a go file cursor specified to the appropriate function in command mode, enter GD to automatically jump to the location of the function definition
Installation and installation of Youcompleteme and Gocode
YCM installation process quite an egg. Step by step.
1 VIM version must be more than 7.4 because my osx10.9 comes with VIM is 7.3 so must be updated
First download a latest version of Vim download from http://www.vim.org/download.php
If the direct make compilation must be a problem a lot of problems specific I will not describe
Follow the procedure below to compile it. Unzip the source into the SRC directory to modify the src/os_unix.c file
In #if!defined (__apple__) &&!defined (__tandem) # define Select Select_declared_wrong #endif前添加 # If defined (__apple__) # include <AvailabilityMacros.h> #endif
return src make clean and then ./configure--with-features=huge--enable-pythoninterp--enable-rubyinterp re make
This time the made Vim is available, otherwise it cannot be used for YCM
Modify the ~/.bash_profile file add a Word
Alias vim= "/applications/developer/tools/vim74/src/vim"
Source a little bit. Vim--version View VIM version if it's 7.4, no problem.
Add Bundle ' Valloric/youcompleteme ' in. vimrc
Then: Bundleinstall
Then execute it under the ~/.vim/bundle/youcompleteme/directory./install.sh
YCM installed the next installation Gocode
Go get Github.com/nsf/gocode
Go Install Github.com/nsf/gocode
Added in. VIMRC: Bundle ' Blackrush/vim-gocode '
Also remember to go to github.com/nsf/gocode/vim/below to execute./update.sh
Re-open VIM, Command mode execution: Bunduleinstall
Ctags and Gotags Installation
Go get github.com/jstemmer/gotags
Go Install github.com/jstemmer/gotags
Add the following in ~/.VIMRC
"Go tagsbundle ' Majutsushi/tagbar ' nmap <F8>: Tagbartoggle<cr>let g:tagbar_type_go = { \ ' ctagstype ': ' G o ', \ ' 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 ' \}
Re-open VIM, Command mode execution: Bunduleinstall
Nerdtree Installation
Add the following directly to the. VIMRC
"Nerdtree use <c-n>bundle ' Scrooloose/nerdtree" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " "" "" "" "" "" "" "" "" "" "" "" "" "Let nerdtreewinpos= ' left ' let Nerdtreewinsize=31let nerdtreechdirmode=1map <C-n>: Nerdtreetoggle<cr>autocmd Bufenter * if (WINNR ("$") = = 1 && exists ("B:nerdtreetype") && B: Nerdtreetype = = "PRIMARY") | Q | endif
Post My./VIMRC configuration is for reference only
"Ui:colorscheme desertset rulerset numberset background=darkset t_co=256set cursorlineset Backspace=indent,eol, Startset fdm=indentset completeopt=longest,menu "Golang" gofmt *.go files after savingfiletype offfiletype plugin indent o Ffset rtp+= $GOROOT/misc/vimfiletype plugin indent onfiletype plugin onsyntax onfiletype indent on "Bundleset nocompatible Let mapleader= "," Set Rtp+=~/.vim/bundle/vundle/call VUNDLE#RC () bundle ' gmarik/vundle ' bundle ' valloric/ Youcompleteme ' bundle ' Cespare/vim-golang ' bundle ' blackrush/vim-gocode ' bundle ' dgryski/vim-godef ' let g:godef_split= 2 "No backupset nobackupset noswapfileset nowb" Encodingset Encoding=utf8 "auto, smart indentset aiset si" Highlight Searc Hset hlsearch "Open file in the Modifiedautocmd bufreadpost *\ if line (" ' \ "") >0&&line ("' \" ") <=lin E ("$") |\exe "normal G ' \" "|\ endif" Go tagsbundle ' Majutsushi/tagbar ' nmap <F8>: Tagbartoggle<cr>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:funct Ions ' \], \ ' SRO ': '. ', \ ' kind2scope ': {\ ' t ': ' CType ', \ ' n ': ' Ntype ' \}, \ ' Scope2k Ind ': {\ ' ctype ': ' t ', \ ' ntype ': ' n ' \}, \ ' Ctagsbin ': ' gotags ', \ ' Ctagsargs ': '-sort-si Lent ' \}autocmd bufwritepre *.go:fmtlet g:gofmt_command = "Goimports" "Nerdtree use <c-n>bundle ' Scrooloose/ner Dtree ' "," "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" = ' Left ' let Nerdtreewinsize=31let nerdtreechdirmode=1map <C-n>: Nerdtreetoggle<cr>autocmd bufenter * IF ( Winnr ("$") = = 1 && exists ("B:nerdtreetype") &&b:nerdtreetype = = "PRIMARY") | Q | endif