vim自动补全:go

1 环境配置

export GOPATH=/home/go

2 在新建GOPATH下新建三个目录

mkdir src pkg bin

src 存放源码
pkg 存放编译生成的文件
bin 存放生成的可执行文件

3 工具安装

  • 安装goimports go get github.com/bradfitz/goimports
  • 安装gocode go get github.com/nsf/gocode
  • 安装godef go get code.google.com/p/rog-go/exp/cmd/godef

4、安装vbundle(安装git:apt-get install git)

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

5、

a) Add following commands to the head of ~/.vimrc.

set nocompatible               " be iMproved
filetype off                   " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required! 
Bundle 'gmarik/vundle'
filetype plugin indent on
syntax on

b) Install vim-go

~$ cd ~/.vim/bundle
~$ git clone https://github.com/fatih/vim-go.git

Add this line to ~/.vimrc.

Plugin 'fatih/vim-go'

Execute :PluginInstall in Vim.    

6、更新

cd $GOPATH/src/github.com/nsf/gocode && vim/update.sh
gocode set propose-builtins true
gocode set lib-path "$GOPATH/pkg/linux_amd64"

7、打开vim,自动补全功能快捷键(ctrl+x+o)

为了方便,将 Ctrl+Space 映射为自动补全快捷键:

imap <C-Space> <C-x><C-o>

 

原文地址:https://www.cnblogs.com/dadream/p/5056727.html