Go language is not as good as the Source Insight editor, the trial of a variety of, Vim is the best, followed by liteide (There are counter-check variable function reference points, modify the line color function), the two can be used together.
The following is a step by step to build the Vim Go language editing environment process.
Ubuntu, for example, assumes that the go development environment is well configured and Git is installed.
Installing Pathogen
Go to http://www.vim.org/scripts/script.php?script_id=2332 to find the latest version of the package ZIP download link below;
After the download, you will get a directory named after the autoload
directory to copy the files pathogen.vim
to ~/.vim/autoload/pathogen.vim
;
Edit the ~/.vimrc
file and join the row at the top call pathogen#infect()
.
Installing the Vim-go plugin
With the plugin Manager installed, you can start installing the plugins we want.
- Executes the
~/.vim/bundle
command after entering the directory git clone https://github.com/fatih/vim-go.git
.
- Edit
~/.vimrc
the file and add the following (the last line is to disable automatic download):0
At this point, the plug-in itself has been installed, can be used according to the instructions of Github.com/fatih/vim-go, which is to point out the code to complete the <C-x><C-o>
prompt, and generally need to .
use after the input operator.
Some of the default highlights are not open in. VIMRC using the following open:
11 1)11
Highlight effect:Installing Neocomplete
If you want real-time code completion prompts, you can install the Neocomplete plug-in to achieve, but it has a higher requirement for VIM version, you can see its home page Github.com/shougo/neocomplete.vim.
- Executes the
~/.vim/bundle
command after entering the directory git clone https://github.com/Shougo/neocomplete.vim.git
.
- Edit
~/.vimrc
the file and join the line let g:neocomplete#enable_at_startup = 1
. This allows you to automatically turn on real-time completion when you start VIM.
安装ctags与gotags
sudo apt-get install ctags,然后 go get -u github.com/jstemmer/gotags
安装 Go 语言的相关解析器。
~/.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'\ }
使用:光标在某变量或函数上,输入gd跳转。ctrl+o返回
安装tagbar
Installed Tagbar plug-in, and install vim-go like, first enter the ~/.vim/bundle
directory. And then execute git clone https://github.com/majutsushi/tagbar.git
.
Edit ~/.vimrc
the file and join the line nmap <F8> :TagbarToggle<CR>
. This is a shortcut key mapping, you can change it into F8
any.
安装nerdtree
Executes the ~/.vim/bundle
command after entering the directory git clone https://github.com/scrooloose/nerdtree.git
.
Edit ~/.vimrc
the file and join the line map <F7> :NERDTreeToggle<CR>
. This way, when you need to browse the directory, you can use the shortcut keys <Ctrl+n>
to bring up the browsing window.
Installing Mark.vim
Download from http://www.vim.org/scripts/script.php?script_id=2666, Open with vim input: so%, see: H vimball
in. VIMRC, add the following to use: The cursor is on a word, ml highlights the word. MF jumps between the same words, MN jumps to the next any highlighted word.
Nmap ml <Plug>markset #高亮或反高亮一个单词 <Plug><Plug>Marksearchanynext # Jump to any next highlighted word <Plug><Plug>marksearchcurrentnext #跳转到当前高亮的下一个单词
Installing Visualmask
Name: |
Visualmask |
: |
HTTP://WWW.VIM.ORG/SCRIPTS/SCRIPT.PHP?SCRIPT_ID=1026 |
Installation: |
Put the downloaded visualmask.vim in the $HOME/.vim/plugin directory. |
Help: |
See the opening section of Visualmask.vim. |
In normal mode, press CTRL+F2 or mm to set the highlight bookmark, jump by F2 or SHIFT+F2, move the cursor to the bookmark, and then press CTRL+F2 or mm to cancel the bookmark.
Use of the process encountered a problem, each time you add a bookmark will be prompted: E197:cannot set Language to "en_US". The 55th line of the Visualmask.vim will be:
": Lan mes en_us"
Change to the following to resolve:
": Lan mes en_us.utf8" G
Install ACK
First install Ack-grep, sudo apt-get install Ack-grep
git clone https://github.com/mileszs/ack.vim.git ~/.vim/bundle/ack.vim
VIMRC Add:
Map <F4>: Ack
The cursor rests on a function or variable name, press F4 to enter, you can search the call at the global
CTRLP Find files quickly
http://www.vim.org/scripts/download_script.php?src_id=19448
Direct <ctrl + p> Enter a filename to quickly locate the file as if it were sublime.
Install the above plug-in, as the editor is enough, basic can be accessible to edit the go code. But for the code, vim can not use the mouse and graphics are inherently incomplete, unable to generate a call graph like source Insight, for the daytime code is less efficient, can only wait for source insight to support the go language. Another: Liteide is an editing tool that supports the identification of function call points, and it also supports editing line discoloration and clearly displays the modified code. But the reference relationship can only find one layer, cannot see the call tree, can be used with vim.
How vim configures the Go language environment