Linux CentOS 7 YouCompleteMe相关配置。

时间:2023-03-09 17:24:20
Linux CentOS 7 YouCompleteMe相关配置。

CentOS 6.5上面弄了2天,以失败告终!!!当作练手了。在网上看到一篇CentOS7.0上安装YouCompleteMe插件的文章,就重新在虚拟机上安装了一个CentOS7,按那个文章执行了一下,花了一天的时间,安装成功了。

文章地址:http://www.tuicool.com/articles/yquEZzb

安装:

1.先安装vundle插件,这个插件可以看作是像360的软件管家,只是这个vundle插件是管理vim插件的(也许还可以管理非vim的插件,我没深究)。利用这插件可以管理很多vim的插件。

$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
【注】没有特别说明,这里命令都代表在$HOME目录下。$表示一般用户,#表示root
如果没有git命令,那就先去安装一个git
$ vim .vimrc
【注】如果没有这个.vimrc文件,可以用root用户查看root用户的$HOME目录下面有没有,如果有的话就拷贝一份到当前普通用户的$HOME下面来,或者自己新建一份也行。如果没有的话,可能是没有安装vim。别看系统能输入vim命令,不一定安装了,到下面的步骤还会再讲这个问题。
配置内容如下,复制粘贴进去即可:
set nocompatible              " be iMproved, required
filetype off " required " set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path) " let Vundle manage Vundle, required
Plugin 'gmarik/vundle' " The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tpope/vim-rails.git'
" 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/'}
" scripts from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
Plugin 'FuzzyFinder'
" scripts not 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'
" ... filetype plugin indent on " required
Bundle 'Valloric/YouCompleteMe'

保存退出,然后在输入vim命令,打开vim编辑器,在vim的命令模式下输入如下命令进行插件安装。(需要安装的插件就配置在.vimrc文件中,看看.vimrc配置文件就清楚了)

:BundleInstall

【注】我安装的时候出现问题,vim居然提示找不到BundleInstall命令,就是说,我输入上面那个安装命令,提示找不到命令,删掉几个字母,按Tab,也没有自动提示补全命令,果然是没有BundleInstall命令。我猜测会不会Bundle也是一个插件,也没有安装,按这个思路搜索了一上午的文章,也没找到解决办法。后来偶然看到一个文章中说执行vi并一定就是打开的vi,也有可能是打开的vim,我就猜测难道我的centos7都没装vim。结果我用虚拟机的软件安装向导一搜索vim,果然vim是可以安装的状态,那就表示我系统没安装,要么就是版本低(我不确定),反正就是安装好vim后,BundleInstall命令才可以用。

安装时有个错误,这是正常的,因为ycm需要手动编译出库文件。

Done! With errors; press l to view log

ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need to compile YCM before using it. Read the docs!

另外,如果有些插件安装失败,那就别管了,注释掉,主要保证YouCompleteMe插件能安装上。

配置YouCompleteMe:

然后到.vim/bundle/YouCompleteMe 下执行命令

$ ./install.sh --clang-complete

参数是为了支持c/c++的补全

【注】执行命令后,可能会报错。我安装的时候是报错了,先报了一个错误,我看了报错信息,大概意思是没有CMake命令。网上搜了一下,安装了CMake,就解决了。

然后可能还会出现报错:

Some folders in /home/sky-tm/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party are empty; you probably forgot to run:    git submodule update --init --recursive

若出现此错误,则按照提示来,继续输入命令:

$git submodule update --init –recursive
等此命令更新完成后,再此执行命令:
$ ./install.sh --clang-complete

YouCompleteMe进行补全时需要查找一个 ycm_global_ycm_extra_conf文件。可以每次在工作目录中放置这个文件,也可以设置全局。全局设置要在. vim rc中添加一行即可。

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

注:.ycm_extra_conf.py 是个隐藏文件,路径在~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py

 
我最后只是把.ycm_extra_conf.py拷贝一份,放到我的$HOME目录下了,然后再配置了一下,增加了一些C/C++标准头文件的路径。还是不太懂那个配置文件的意思。

另外,我想配置一下,让这个只提供C,C++相关的提示,不要其他语言的提示,应该怎么做?

另外,这个文章中的.vimrc配置并不是最终的,到此为止,我试了一下,效果并不是很好,也许我还没有发挥它的最大威力,不过个人感觉确实不咋地,又在网上找了一份配置,就拷贝的一份.vimrc文件,然后修改了一些格式上的错误(代码中用的中文标点引起错误),然后试了一下,效果还可以,居然按F5可以编译执行,有种VS上的感觉了。注意一点,更换了.vimrc文件之后,还是要执行BundleInstall,因为第二份的.vimrc配置文件增加了一些插件,需要BundleInstall一下.

记录本人电脑上vim的一些操作方式:

Ctrl + ]  跳转到函数定义
Ctrl +t   返回函数调用处

F5 编译运行C/C++程序(另外,关于unix网络编程源代码使用,这里不能用F5来编译了,应该用gcc –o name name.c -lunp)