首先在~下新建目录.vim和配置文件.vimrc,.vimrc内容如下:
syntax on set nocompatible filetype off set rtp+=~/.vim/bundle/Vundle.vim
set tags=~/tags call vundle#begin() Plugin 'gmarik/Vundle.vim' " Plugin 'Valloric/YouCompleteMe' Plugin 'SirVer/ultisnips' Plugin 'fatih/vim-go' Plugin 'tmhedberg/SimpylFold' Plugin 'scrooloose/syntastic' Plugin 'nvie/vim-flake8' Plugin 'scrooloose/nerdtree' Plugin 'vim-scripts/indentpython.vim' Plugin 'kien/ctrlp.vim' Plugin 'dgryski/vim-godef' Plugin 'Blackrush/vim-gocode' Plugin 'majutsushi/tagbar' Plugin 'python-mode/python-mode' call vundle#end() " required filetype plugin indent on " required set go= " 不要图形按钮 set guifont=Courier_New:h10:cANSI " 设置字体 autocmd InsertLeave * se nocul " 用浅色高亮当前行 autocmd InsertEnter * se cul " 用浅色高亮当前行 autocmd BufWritePre *.go :Fmt set nu set ruler " 显示标尺 set fileencodings=ucs-bom,utf-8,utf-16,gbk,big5,gb18030,latin1 set enc=utf8 set fencs=utf8,gbk,gb2312,gb18030 set showcmd " 输入的命令显示出来,看的清楚些 set cmdheight=1 " 命令行(在状态行下)的高度,设置为1 set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228) autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口 map <C-e> :NERDTreeToggle<CR> nnoremap gb <C-O> nnoremap <space> zn function! CleverTab() if strpart( getline('.'), 0, col('.')-1 ) =~ '^s*$' return "<Tab>" else return "<C-N>" endif endfunction inoremap <expr> <CR> pumvisible() ? "<C-n>" : "<CR>" " vim-go settings let g:go_fmt_command = "goimports" let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' let g:ycm_key_list_select_completion = ['<Down>', '<c-n>'] ""let g:ycm_key_list_previous_completion=['<c-p>'] let g:ycm_key_list_previous_completion = ['<Up>', '<c-p>'] let g:UltiSnipsExpandTrigger = "<tab>" let g:UltiSnipsJumpForwardTrigger = "<tab>" let g:UltiSnipsJumpBackwardTrigger = "<s-tab>" let g:UltiSnipsListSnippets="<c-e> " let g:ycm_confirm_extra_conf=0 "关闭加载.ycm_extra_conf.py提示 let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict' let g:go_version_warning = 0 nnoremap <leader>gf :YcmCompleter GoToDefinitionElseDeclaration<CR> nnoremap <leader>gr :YcmCompleter GoToDeclaration<CR> let g:pymode_rope_goto_definition_bind = 'gd' if !empty(glob("~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py")) let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py" endif " new version if !empty(glob("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py")) let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py" endif au BufNewFile,BufRead *.py set tabstop=4 | set softtabstop=4 | set shiftwidth=4 | set textwidth=79 | set expandtab | set autoindent | set fileformat=unix | set encoding=utf-8 let python_highlight_all=1 au BufNewFile,BufRead *.go set tabstop=4 | set softtabstop=4 | set autoindent
然后用vim随便打开一个文件,执行:PluginInstall命令 等待安装完毕后,就安装python和golang自动提示工具
python自动提示安装方法:
http://www.jb51.net/article/58009.htm
首先在git克隆pydiction到本地,然后再配置,所有命令如下:
cd ~/.vim/bundle/ git clone https://github.com/rkulla/pydiction.git mkdir -p ~/.vim/tools/pydiction cp -r pydiction/after ~/.vim cp pydiction/complete-dict ~/.vim/tools/pydiction
然后在.vimrc中添加如下几行(上边我的配置文件中已经添加好)
filetype plugin on let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict' let g:pydiction_menu_height = 3
golang自动提示安装方法:
http://blog.sina.com.cn/s/blog_a126a9550101bee7.html
前提:go的编译、运行环境都已经搭建完毕。
go的高亮在安装目录下的misc/vim/readme.txt文件说明,就是执行shell命令。
下面来介绍自动补全gocode在vim配置
设置环境变量GOPATH=$HOME/goprojects,加入PATH=$GOPATH/bin,最后gocede命令会存在于这个目录下。
执行go get -u github.com/nsf/gocode,gocode的代码自动会下载到GOPATH中,进入$GOPATH/src/github.com/nsf/gocode,执行./vim/update.bash,执行gocode命令看安装是否成功。
还需要添加 filetype plugin on在.vimrc中,
至此,vim可用ctrl+x+o自动补全go语言。
2018.4.19
补充。。。
上次配置好了之后,在python中跳转有问题,总会报错:tags找不到文件,查了查,应该是ctags没有用好,下面说下怎么用:
1 安装ctags(不多说,网上有的是方法)
2 执行ctags -R命令,生成一个tags文件
3 在~/.vimrc中添加,我的tags文件路径就在~/tags,所以添加下边这一行就可以了(上边的配置文件我已经给修改添加了,可直接复制)
set tags=~/tags