Vim 自动补全--YouCompleteMe

Vim 自动补全--YouCompleteMe

一、安装vim的插件管理器Vundle
1.如果自己用户目录下不存在.vim/bundle,可以使用如下命令进行创建

mkdir -p ~/.vim/bundle

2.把Vbundle从github上clone下来,命令如下(如果之前未安装git,请安装后执行如下命令)

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

3.在自己用户目录下的.vimrc中添加如下内容

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vundle 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' Plugin 'Valloric/YouCompleteMe' " 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/'}
" Avoid a name conflict with L9 "Plugin 'user/L9',{'name': 'newL9'}

" 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中执行如下命令

:PluginInstall

5.出现的界面如下图

选定你要安装的YouCompleteMe插件回车,安装其他插件的方式雷同。
6.等待插件安装的过程比较漫长,当装太由Processing变为done!时说明插件安装成功了。
安装过程如下图

成功后如下图
那个
7.如果上一步那个漫长过程成功了,说明你的YouCompleteMe已经下载成功了,可以对其进行编译了
(1)首先安装编译需要的工具(最好提前安装上python,如果安装过程中出现失败,请结合系统单个工具单独安装,或百度查找其他安装方式),已经安装的请忽略这步。

sudo apt-get install gcc g++ cmake python-dev ctags

(2)工具安装完成后开始进行编译工作

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer

这个过程也是比较慢的,因为在编译过程中他会去下载clang相关内容并对其进行编译最终生成ycm_support_libs
编译配置过程

下载过程

下载并编译完成

8.上述过程都成功执行之后,你应该处于如下目录里面

~/.vim/bundle/YouCompleteMe/

如果不在那个目录下执行如下命令

cd ~/.vim/bundle/YouCompleteMe/

把执行如下命令,把.ycm_extra_conf.py(隐藏文件)文件拷贝到你自己的代码目录下:

cp third_party/ycmd/examples/.ycm_extra_conf.py /home/fas/workplace/FAS/

其中FAS为我的C++开源服务器框架代码根文件夹名。
到自己的代码目录下配置.ycm_extra_conf.py文件比葫芦画瓢就行了,一下是.ycm_extra_conf.py的部分内容,其中自己的代码路径可以有n个。

# These are the compilation flags that will be used in case there's no
# compilation database set (by default,one is not set).
# CHANGE THIS LIST OF FLAGS. YES,THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall','-Wextra','-Werror','-Wc++98-compat','-Wno-long-long','-Wno-variadic-macros','-fexceptions','-DNDEBUG',# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',# THIS IS IMPORTANT! Without a "-std=<something>" flag,clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project,you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project,you would set this to 'c' instead of 'c++'.
'-x','c++','-isystem','../BoostParts',# This path will only work on OS X,but extra paths that don't exist are not
# harmful
'/System/Library/Frameworks/Python.framework/Headers','../llvm/include','../llvm/tools/clang/include','-I','自己代码路径1','自己代码路径2','自己代码路径3','./ClangCompleter','./tests/gmock/gtest','./tests/gmock/gtest/include','./tests/gmock','./tests/gmock/include',]

9拓展内容,你在使用vim的过程中,如果有什么地方感觉不太符合自己的需求可以参考下拓展内容:

" YCM " 允许自动加载.ycm_extra_conf.py,不再提示                         
let g:ycm_confirm_extra_conf=0                                     
" 补全功能在注释中同样有效 let g:ycm_complete_in_comments=1 " 开启tags补全引擎                                                 
let g:ycm_collect_identifiers_from_tags_files=1                    
" 键入第一个字符时就开始列出匹配项 let g:ycm_min_num_of_chars_for_completion=1 " YCM相关快捷键,分别是\gl,\gf,\gg                                                    
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>              
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>               
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>

其中,

g:ycm_confirm_extra_conf如果不设为0的话,用vim每次打开代码文件,YCM都会提示是否确认加载某某.ycm_extra_conf.py文件;
ycm_collect_identifiers_from_tags_files设为1,指定YCM收集传统tags文件的信息,另外当tags改变时,YCM会重新索引它们。YCM对tags文件的格式有特殊的要求:The only supported tag format is the Exuberant Ctags format. The format from "plain" ctags is NOT supported. Ctags needs to be called with the --fields=+l option (that's a lowercase L,not a one) because YCM needs the language:<lang> field in the tags output。如有问题请参阅YCM官网相关FAQ;
比如引入C++tags:
 " 引入 C++ 标准库tags set tags+=/data/misc/vim/stdcpp.tags
3个快捷键设置是用来快速跳转到符号声明或定义的。我往往只用gg,即将光标定位到某个符号上,按\键后(默认的leader键是\),快速按两次g键,将跳转到该符号的声明或定义位置(Tips: 按<ctrl>+o返回)

其他技巧:

执行:YcmDiags显示所有错误,它其实是打开了一个location list窗口,也可能通过:lopen打开. 使用:lclose可以关闭
有些系统函数如fopen,strcpy如果不智能提示,可以按<Ctrl>+<Space>键。
如果有的文件死活无法正确提示(如果结构体之类),请检查一下文件编码,改成utf-8。(vim中 :set fileencoding=utf8)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全局的情况下:即所有用户都能用这个配置文件地址:/etc/vimrc在文件中添加:setfileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936settermencoding=utf-8setencoding=utf-8如果只修改个人的vim配置情况:需要把/etc/
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的文书编辑器则不一定会存在。但是目前我们使用比较多的是vim编辑器。vim具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计。相关文章:史上最全Vim快捷键键位图—入门到进阶什么是vim
      vim正则匹配:空行:/^$/  /^[\t]*$/注释行:/^#/ /^[\t]*#/:1,$s/\([Rr]\)oot/\1ename/:1,$s/\(square\)and\(fair\)/\2and\1/ 
$select-editorSelectaneditor.Tochangelater,run'select-editor'.1./bin/ed2./binano<----easiest3./usr/bin/code4./usr/bin/vim.basic5./usr/bin/vim.tinyChoose1-5[2]:4
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下预览图安装工具:u盘、manjarokdeminimal20.0.3、win32DiskImager提取码:qt9f进bios、选择u盘启动、改语言、改时区、挂载分区(文件系统ext4、在200M左右的一个FAT分区上挂载/boot/efi)、安装安装很简单,按提示
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置vi文本编译器,其他的文本编译器则不一定存在很多软件的编译接口都会主动调用vivim有很强的程序编译能力,可以主动的一字体颜色辨别语法的正确性,方便程序设计因为程序简单,编译速度相当快vi的使用一般命令模
主机名字太长,怎么修改?  1.sudovim/etc/hostname 修改内容为wel,  本地主机名 2.sudovim/etc/hosts      修改主机名为wel,用于网络连接中主机名的识别 3.reboot 
目录#事故现场#事故原因#解决方法方法一:使用notepad转换方法二:使用vscode转换方法三:使用vim转换#参考#事故现场执行shell脚本文件,报错::notfound.sh:6:coreinstall.sh:查看脚本文件第6行,发现是空行;#事故原因window下的换行是回车符+换行符,也就是\r\n,而unix下是换行符\n
1、保存并退出linux下安装好了vim以及gcc后,我们开始新建一个c文件,例如:vimtest.c之后进入vim的编辑框中,点击i进入插入模式,开始编辑程序,当你编写好自己的程序之后,按Esc退出插入编辑状态,然后输入冒号加wq,点击Enter即可,完整的命令如下:wq如下图:  退出后,如果想要编译
概述使用VIM作简单字数统计背景想做一个简单的字数统计环境OSwin10shellmintty-2.9.41.需求概述需求需求统计文段内字符的数量支持自定义字符集2.方案1:vim自带统计概述vim自带方案操作定位到文段内某行vi
经典版下面这个键位图应该是大家最常看见的经典版了。对应的简体中文版其实经典版是一系列的入门教程键位图的组合结果,下面是不同编辑模式下的键位图。 
ssh是一个安全连接协议。作用两个:1.远程连接协议,2.远程文件传输协议协议默认端口为:22。 修改默认端口,再到ssh服务配置文件位置  vim/etc/ssh/ssh_config这条命令就可以修改了。按下ESC键,再输入:x 也可以退出vim。(和:q! 相同)修改注意:1.端口号在0-65535之间。2.别人
Vim是一个类似于Vi的著名的功能强大、高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性。VIM是自由软件。Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Emacs的不同变体。1999年Emacs被选为Linuxworld文本编辑分类的优胜者,Vim屈居第二。但在2000年2月Vim赢
在Vim中,有时需要将tab转换成space。使用ret命令(replacetab)。[range]ret[ab]![new-tabstop]举例:将第一行到文件尾的tab转换成space,每个tab用4个space替代。:setexpandtab:%ret!4如果没有给定4,则用当前的tab宽度设定替换为space。 相关配置文件命令::settabstop=4设
分屏命令记不得文件名就输入.可浏览文件命令英文功能:sp[文件名]split横向分屏:vsp[文件名]verticalsplit纵向分屏    切换分屏窗口先按Ctrlw切换窗口命令英文功能 wwindow切换下一个窗口 rreverse互换窗口 c
1查看ctags支持的语言ctags--list-languages2查看语言和扩展名的对应关系ctags--list-maps 3对当前目录下所有ctags支持的语言格式文件生成tagsctags-R*缺点很明显,tags会非常大,tags生成会非常慢,而且代码跳转会卡顿。4只对特定文件生成tagsctags`find-name"*.h"`ct
vim基本命令 $vimtutor可以查看基本的vim操作1h(left)j(down)k(up)l(right)q!wqi:insertbeforethecursor(insert)插队嘛,肯定在光标前面A:appendaftertheline(appending)2dw:删除一个单词,保留光标前面部分d$:删除光标之后的同行
~/.vimrc内容如下:setnocompatiblefiletypeoffsetrtp+=~/.vim/bundle/Vundle.vimcallvundle#begin()Plugin'VundleVim/Vundle.vim'Plugin'tpope/vim-fugitive'Plugin'tpope/vim-unimpaired'Plugin'tpope/vim-repeat'Plu
程序:硬盘静态的代码  占用磁盘空间进程:内存运行计算的代码 占用CPU运行内存父进程与子进程  树型结构进程唯一标识: PID僵尸进程找到父进程杀掉  孤儿进程疯狂要内存  危害大 pstree [选项]-a显示完整命令行   -p 查看PID [PID或用户
~/.vimrc"Configurationfileforvimsetmodelines=0 "CVE-2007-2438setnumber"setrelativenumber"显示相对行号(这个非常重要,慢慢体会)setcursorlinesetcursorcolumnsetrulersetscrollbindsetencoding=utf-8colormolokaisyntaxon"开启