linux安装YouCompleteMe(很详细)


YouCompleteMe是个功能强大的代码补全插件,但是安装过程非常困难,这里带不太熟悉的朋友进行安装(非常详细)当遇到没有权限是使用sudo执行

目前博主使用的linux发行版是debian9,不过只要是linux安装过程都是一样的

===================================================================

对内容进行补充,当从git拉取或下载子模块的时候可能出现卡顿或下载失败的情况,很有可能是因为网络的原因;请不用担心,多尝试下载几次,如果出现长时间下载一直不动的情况,可以抓取对应端口的数据包。看看有没有数据,没有数据的话按Ctrl-C中断重来

查看连接的端口命令,找到foreign address为443的端口,然后得到对应local address的端口号
netstat -tnp | grep 443
抓取数据包
sudo tcpdump -s 0 -X ‘tcp dst port 本地连接的端口号’

检查vim版本查看是否支持python

在终端输入vim进入vim界面

$ vim

进入编辑模式输入:version
在这里插入图片描述
找到其中的版本号和python或者python3
python和python3只需要其中一个是+号就可以了
如果你的vim版本号低于7.4.1578那么就需要重新安装一个高于此版本号的vim
如果你的vim是-python代表不支持python可能需要进行源码安装或者安装vim-nox

$ apt remove vim
$ apt install vim-nox

下载插件管理器Vundle

$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

打开.vimrc输入以下内容:

$ vim ~/.vimrc

set nocompatible
filetype on

安装YouCompleteMe前的准备工作

安装YCM前需要安装进行一些准备工作,下载一些需要的东西
安装python-dev, python3-dev

$ apt install python-dev python3-dev

安装开发工具

$ apt install build-essential cmake
//或者
$ apt install build-essential cmake3

Fedora 27及更高版本:

$ dnf install cmake gcc-c++ make python3-devel

从github上clone YouCompleteMe

cd到~/.vim/bundle目录下进行克隆

$ cd ~/.vim/bundle
$ git clone https://github.com/ycm-core/YouCompleteMe.git

进入YouCompleteMe目录下载必要的子模块,这里需要注意,以前能顺利下载的模块更改了url地址导致被墙不能下载成功,需要更新地址,所以此步骤和之前网上有些不太一样

$ cd ~/.vim/bundle/YouCompleteMe
$ sudo git submodule update --init        // 没有–recursive!!! 如果加了这个选项之后修改的url地址会被改回去!

这一步就是修改url地址了,到ycmd目录下打开.gitmodules文件

$ cd third_party/ycmd
$ vim .gitmodules

找到[submodule “third_party/go/src/golang.org/x/tools”]
我们可以看到url地址跟其他大不相同,并不是github中的
修改 url = https://github.com/golang/tools

[submodule “third_party/go/src/golang.org/x/tools”]
   path = third_party/go/src/golang.org/x/tools
   url = https://github.com/golang/tools
   ignore = dirty

保存并退出,在当前目录继续下载子模块

$ git submodule update --init --recursive

下载完成后就可以进行编译了

编译YCM

cd到YouCompleteMe的跟目录下去执行install.py脚本

$ cd ~/.vim/bundle/YouCompleteMe
$ python3 install.py --clang-completer     //添加c/c++语言的补全,或者使用-all不全所有语言
// python编译使用下列
// python install.py --clang-completer
在这里插入图片描述

编译完成,但是还不能使用,还需要进行一些配置

配置文件

编译完成之后打开~/.vimrc进行配置,在这里贴上我使用的配置,想要设置自己的配置可以去github查看
YouCompleteMe

call vundle#begin()

set runtimepath+=~/.vim/bundle/YouCompleteMe
"Plugin 'Valloric/YouCompleteMe'
autocmd InsertLeave * if pumvisible() == 0|pclose|endif " 离开插入模式后自动关闭预览窗口
let g:ycm_collect_identifiers_from_tags_files=1         " 开启YCM基于标签引擎
let g:syntastic_ignore_files=[".*\.py$"]
let g:ycm_seed_identifiers_with_syntax = 1         " 语法关键字补全
let g:ycm_confirm_extra_conf = 0                   " 关闭加载.ycm_extra_conf.py提示
let g:ycm_key_list_select_completion = ['<c-n>','<Down>']" 没有这个会拦截掉tab
let g:ycm_key_list_previous_completion = ['<c-p>','<Up>']
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
let g:ycm_server_python_interpreter='/usr/bin/python3'
“let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 1       " 语法检查
let g:ycm_use_clangd = 0
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"        " 回车即选中当前项
nnoremap <c-j> :YcmCompleter GoToDefinitionElseDeclaration<CR>  " 跳转到定义处
let g:ycm_min_num_of_chars_for_completion = 2		      " 从第2歌键入字符就开始罗列匹配项

call vundle#end()

大功告成!
在这里插入图片描述

如果你的vim还是不能补全的话就需要在~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py这个文件下添加一些内容了

在这里插入图片描述找到你没有的内容添加进去

  • 9
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答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中了。您可以根据需要自定义配置,以适应您的开发环境。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值