CentOS 7.4 用VIM搭建GOIDE

转载 2018年04月17日 20:49:07

首先需要安装go

省略…

升级VIM为VIM8

cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)

安装ycm过程中会提示:YouCompleteMe unavailable : YouCompleteMe unavailable: requires Vim 7.4.1578+

升级vim

# 移除旧版本
sudo yum remove vim -y
# 安装必要组件
sudo yum install ncurses-devel python-devel -y
yum -y install lua lua-devel
# 下载源码编译安装
git clone https://github.com/vim/vim.git
cd vim/src
# 根据自己实际情况设置编译参数
./configure --with-features=huge --enable-pythoninterp=yes --enable-cscope --enable-fontset --with-python-config-dir=/usr/lib64/python2.7/config --enable-luainterp
make
sudo make install

编译参数说明:
–with-features=huge:支持最大特性
–enable-rubyinterp:打开对ruby编写的插件的支持
–enable-pythoninterp:打开对python编写的插件的支持
–enable-python3interp:打开对python3编写的插件的支持
–enable-luainterp:打开对lua编写的插件的支持
–enable-perlinterp:打开对perl编写的插件的支持
–enable-multibyte:打开多字节支持,可以在Vim中输入中文
–enable-cscope:打开对cscope的支持
–with-python-config-dir=/usr/lib64/python2.7/config 指定python 路径
–with-python-config-dir=/usr/lib64/python3.5/config 指定python3路径

注意:必须带上Python编写插件支持,最好带上Python路径,否则使用时会报这个错误:YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support

编译安装好Vim后,默然是安装在/usr/local/bin目录下,所以把该目录加入到PATH方便terminal全局使用:

sudo nano /etc/profile

在尾部添加:

export PATH=$PATH:/usr/local/bin/vim

然后使环境变量生效:

source /etc/profile

安装YCM

Vundle是Vim的插件管理工具,官方文档:https://github.com/VundleVim/Vundle.vim

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim ~/.vimrc
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" 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 your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}

Bundle 'altercation/vim-colors-solarized'
Plugin 'vim-scripts/OmniCppComplete'
Plugin 'Valloric/YouCompleteMe'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

syntax enable
colorscheme monokai

let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

执行插件安装

vim +PluginInstall +qall
sudo yum install cmake -y
cd ~/.vim/bundle/YouCompleteMe  
./install.py --go-completer

安装GO-IDE

git clone https://github.com/farazdagi/vim-go-ide.git ~/.vim_go_runtime
sh ~/.vim_go_runtime/bin/install

vim -u ~/.vimrc.go测试

mkdir -p /usr/local/goextra
export GOPATH=/usr/local/goextra

启动vim,执行

:GoInstallBinaries

/usr/local/goextra加入环境变量

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

执行,组合ycm和vimgo,因为ycm可以自动补全,vimgo需要ctrl+x,ctrl+o

 cp .vimrc .vim_go_runtime/custom_config.vim
 sh ~/.vim_go_runtime/bin/install 

其他探索

最后,加一些快捷键:vim ~/.vimrc.go
在最后添加一些常用快捷键映射

let mapleader = ","
map ,g :YcmCompleter GoTo <Esc>//这个无法跟踪vendor目录里的
map ,d :GoDef <Esc>//这个可以跟踪vendor目录的
map ,r :GoRun <Esc> //执行
map ,t :GoTest <Esc> //测试
map ,f :GoTestFunc <Esc> //执行光标所在测试函数
map <C-n> :cnext<CR> //显示下一个错误
map <C-m> :cprevious<CR> //显示上一个错误
nnoremap <leader>a :cclose<CR> //关闭错误飘窗
set autowrite //自动保存
autocmd FileType go nmap <Leader>c <Plug>(go-coverage) //生成覆盖率,用默认浏览器打开结果

这样就可以在定位到函数的时候,直接 ,gg 就跳转到定义,看完后ctrl+o退回来。
此处还有vimgo的一些其他命令,很强大,例如vafdafyafdifvifyif 自己测试下吧。

export GOPATH=/usr/local/go/extra/
gometalinter --install //安装gometalinter

vim ~/.vimrc.go
//添加
map ,l :GoMetaLinter <Esc> //快捷键,l即可执行GoMetaLinter
vim ~/.bashrc
//添加
alias gp='export GOPATH=`pwd`' //这样每次在所需要的工程目录,直接gp就可以设置gopath为当前目录

更多文档参考:
http://dreamlikes.cn/archives/940
https://farazdagi.com/2015/vim-as-go-language-ide/
https://github.com/fatih/vim-go
https://github.com/Valloric/YouCompleteMe

YouCompleteMe unavailable: requires Vim 7.4.1578+

版本问题 ubuntu 14.05 安装完YouCompleteMe后不生效,提示:YouCompleteMe unavailable : requires Vim 7.4.143 经过检索与...
  • u012421976
  • u012421976
  • 2017-11-10 16:28:17
  • 1661

Ubuntu14.04+vim8.0下Youcompleteme插件 安装

安装YouCompleteMe插件(下文简称YCM)要求vim的版本是vim 7.4.1578 及以上,且支持Python2或Python3。不过每个人在安装过程中所遇见的问题可能是不相同的。下面是我...
  • WXCWDMDS
  • WXCWDMDS
  • 2018-03-29 21:09:43
  • 16

YouCompleteMe unavailable : requires Vim 7.4.143

sudo add-apt-repository ppa:jonathonf/vim sudo apt-get update && sudo apt-get upgrade
  • fdaopeng
  • fdaopeng
  • 2016-11-24 20:51:15
  • 3547

Ubuntu14.04下编译安装Vim74+Vim-gdb

手动编译安装Vim74,首先先安装编译所需的依赖库和头文件。 $ sudo apt-get build-dep vim然后再编译,如果依赖问题没有解决可能会出现这个提示: no terminal l...
  • leaf5022
  • leaf5022
  • 2014-03-10 15:36:23
  • 6702

Ubuntu 搭建强大的 IDE —— Vim + Vundle + 插件(上)

本文描述如何在 Ubuntu 环境中利用插件管理工具 Vundle 搭建一个 Vim 开发环境,从而提高在 Linux 下使用 Vim 进行编程的效率。安装 Vim  在 Ubuntu 上安装 Vim...
  • luckydarcy
  • luckydarcy
  • 2017-08-05 19:40:00
  • 11286

Centos7安装vim8.0 + YouCompleteMe

前言为vim安装YouCompleteMe我已经是不止一次了,两次ubuntu,一次MacOS,一次阿里云的centos..........
  • nzyalj
  • nzyalj
  • 2017-07-18 23:20:08
  • 10722

vim 插件 youcompleteme full install

下载 youcompleteme 源码git clone https://github.com/Valloric/YouCompleteMe.git下载后执行下面命令下载第三方依赖,执行命令后发现 t...
  • u012675539
  • u012675539
  • 2016-05-24 14:25:44
  • 5936

关于开启VIM的Python支持

http://www.tuicool.com/articles/jYvMFv 如果你要在VIM中增加诸如YouCompleteMe这一类的插件的话,那么你需要VIM有Python的支持,这个...
  • forlong401
  • forlong401
  • 2015-01-03 02:57:58
  • 13019

YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+)

安装YouCompleteMe出现以下错误,YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+)解决该...
  • Notzuonotdied
  • Notzuonotdied
  • 2017-02-02 16:52:58
  • 7082

折腾vim YouCompleteMe

服务器上的vim版本太低,安装YouCompleteMe居然要7.3.584版本以上的,鬼知道那个是7.3.584 ……安装7.4吧,命令: >cd vim74 >./configur...
  • biubiuv
  • biubiuv
  • 2015-05-09 14:37:39
  • 2510
收藏助手
不良信息举报
您举报文章:CentOS 7.4 用VIM搭建GOIDE
举报原因:
原因补充:

(最多只允许输入30个字)