CentOS7下Vim简单配置YouCompleteMe心得

生如夏花之绚烂,死如秋叶之静美。
                                   —— 《生如夏花》

前言

关于YouCompleteMe

YCM作为vim史上最强大的插件,同时也是vim史上最难安装的插件。
  博主自行编译参考了数篇blog折腾两天,刚爬出一个坑接着就掉进了下一个坑,最终由于系统环境不同等因素,全部失败(QAQ)。
  对于初入vim的萌新而言,YCM手动编译安装无异于作死,头铁的老铁可以尝试。
  如遇各种问题,请自行google

对于不想折腾的老铁,想快速配置YCM,vimplus是一个不错的选择。

vimplus是由国内大佬chxuan制作的自动配置程序 由于 vimplus 内置了 YouCompleteMe, 同时配置了其他便捷的插件,并且会自动进行编译,十分省心,对于初入vim编程的新手十分友善。vimplus安装过程比较久,请耐心等待。如果安装失败, 请自行google或于作者github/码云上询求解决方案。

版本要求
centos7及其以上64位系统。
ps:由于系统环境不同出现的问题可能也不同,以下为本文配置CentOS版本:

 rpm -q centos-release
 "CentOS Linux release 7.4.1708 (Core)

  • 配置过程中踩到的坑

    • 用户模式下,sudo命令不能使用

    • 在root模式下配置好后,root模式支持代码补全,用户模式不支持

    • vim版本低

    • gcc版本不支持c++11

    • vim不支持python2/3   

开始配置

使sudo可以在用户模式下使用

su
cd /etc/
chmod 660 sudoers
vim sudoers
" 找到:          root        ALL = (ALL)        ALL  
" 在下一行添加:   用户名        ALL = (ALL)        ALL
" 例如:          abouttime        ALL=(ALL)        ALL
" 保存退出
chmod 440 sudoers
" 退出root模式

更新yum

sudo yum upgrade
sudo yum update

下载git

sudo yum install git

升级gcc

sudo yum install centos-release-scl -y
sudo yum install devtoolset-3-toolchain -y
sudo yum install gcc-c++
sudo scl enable devtoolset-3 bash

升级python

sudo yum install python-devel

vim升级

(可选)删除旧版vim

su
rpm -qa|grep vim
rpm -e vim-minimal-7.4.160-2.el7.x86_64 vim-enhanced-7.4.160-2.el7.x86_64 vim-common-7.4.160-2.el7.x86_64 --nodeps

用户模式

cd ~
sudo yum install ncurses-devel
wget https://github.com/vim/vim/archive/master.zip
unzip master.zip
cd vim-master
cd src/
./configure --with-features=huge -enable-pythoninterp --with-python-config-dir=/usr/bin/python2.7/config
"注意 这里的--with-python-config-dir=/usr/lib/python2.7/config 
等号后的路径不一定相同,找到 config 所在路径。"
make
sudo make install

升级完成后查看vim版本

vim --version

检查是否同下图标记一致
这里写图片描述

(可选)之前没有删除旧版vim
默认新的vim是安在/usr/local/bin/中的,但是PATH中会首先找到/usr/bin/中旧的vim,如果没有删除旧版vim,可以输入下面的命令来使命令行中的vim指令指向 /usr/local/bin/vim 的程序

alias vim='/usr/local/bin/vim'

安装vimplus

git clone https://github.com/chxuan/vimplus.git
cd ./vimplus 
./install.sh

详见github
https://github.com/chxuan/vimplus
(个性化及快捷键介绍等,请阅读官方文档)

安装完成后尝试用vim编辑文件,如果出现以下报错:

The ycmd server SHUT DOWN (restart with ':YcmRestartServer').
YCM core library not detected; you need to compile YCM
before using it. Follow the instructions in thedocumentation.

用户模式

cd ~
cd .vim/bundle/YouCompleteMe/
ls
"有install.py文件,执行下面命令"
python install.py

执行完成后,YCM就可以正常使用了。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CentOS 7 中的 Vim 插件 youcompleteme 的安装步骤如下: 1. 安装必要的依赖包: ``` sudo yum install cmake gcc-c++ python3-devel ``` 2. 安装 Vim 和 Vundle(一个 Vim 插件管理器): ``` sudo yum install vim git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim ``` 3. 在 Vim 配置文件中添加以下内容: ``` 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 '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 ``` 4. 在 Vim 中安装插件: 打开 Vim,输入`:PluginInstall`,回车即可。 5. 安装 YouCompleteMe: ``` cd ~/.vim/bundle/YouCompleteMe python3 install.py --all ``` 6. 重启 Vim,即可使用 YouCompleteMe 插件了。 注意:如果你需要 C++ 补全功能,还需要安装 Clang,详情请参考 YouCompleteMe 的官方文档。 ### 回答2: 在CentOS 7上安装vim插件YouCompleteMe,您可以按照以下步骤进行操作: 1. 首先,确保您的CentOS 7系统已经安装了vim和cmake。如果没有安装,可以使用以下命令安装: ``` sudo yum install vim cmake ``` 2. 安装YouCompleteMe插件依赖的一些软件包。打开终端,运行以下命令: ``` sudo yum install python-devel python3-devel ``` 3. 下载YouCompleteMe插件的源代码。您可以在GitHub的YouCompleteMe项目页面上找到源代码的下载链接。使用git命令克隆源代码库到本地: ``` git clone https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe ``` 4. 切换到插件的目录,并构建插件。进入YouCompleteMe目录: ``` cd ~/.vim/bundle/YouCompleteMe ``` 5. 使用下面的命令来构建YouCompleteMe插件: ``` python3 install.py --clangd-completer ``` 6. 构建完成后,启动vim编辑器。在vim中,输入以下命令来安装插件的管理工具vim-plug(如果您已经安装了其他插件管理工具,您可以使用该工具): ``` curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim ``` 7. 编辑您的vim配置文件,并按照以下示例添加YouCompleteMe插件的配置: ``` call plug#begin('~/.vim/plugged') Plug 'ycm-core/YouCompleteMe' call plug#end() ``` 8. 保存并退出vim配置文件后,重新打开vim并执行以下命令,安装插件: ``` :PlugInstall ``` 9. 插件安装完成后,您可以使用YouCompleteMe插件来提供自动补全和代码建议。 ### 回答3: 在CentOS 7上安装YouCompleteMe插件,需要进行以下步骤: 1. 首先,确保已经安装了vim和python-devel: ``` sudo yum install vim python-devel ``` 2. 安装CMake(用于编译YouCompleteMe的依赖项): ``` sudo yum install cmake ``` 3. 使用git克隆YouCompleteMe仓库: ``` git clone https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe ``` 4. 进入YouCompleteMe目录,并编译插件: ``` cd ~/.vim/bundle/YouCompleteMe python3 install.py --clang-completer ``` 这里使用了`--clang-completer`选项来启用C/C++代码补全。如果需要其他语言的补全支持,可以查阅YouCompleteMe的文档并添加相应的选项。 5. 最后,编辑vim配置文件,添加YouCompleteMe插件的设置: ``` vi ~/.vimrc ``` 在文件中添加以下内容: ``` set nocompatible set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' Plugin 'Valloric/YouCompleteMe' call vundle#end() ``` 6. 保存并退出vim,然后重新打开vim。运行`:PluginInstall`命令,安装YouCompleteMe插件: ``` :PluginInstall ``` 这样,YouCompleteMe插件就成功安装到CentOS 7下的vim中了。您可以根据需要自定义配置,以适应您的开发环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值