vim 安装插件

1 简介

  • 插件介绍:YouCompleteMe是一款针对Vim的快速,即用型的模糊搜索代码补全引擎。包括以下几种引擎:
    • 基于标识符的引擎,可与每种编程语言一起使用
    • 基于Clang的引擎,为C / C ++ / Objective-C / Objective-C ++(C系列)提供本地语义代码补全
    • 基于Jedi的Python 2和3的补全引擎
    • 基于OmniSharp的C#补全引擎
    • Go的GocodeGodef语义引擎的组合,
    • 基于TSServer的TypeScript完成引擎,
    • 基于Tern的JavaScript补全引擎,
    • 基于racer的Rust补全引擎,
    • 基于jdt.ls的Java实验性补全引擎。
    • 基于omnifunc的补全引擎,它使用来自Vim的omnicomplete系统的数据为许多其他语言(Ruby,PHP等)提供语义补全。
    • 基于UltiSnips的代码片补全引擎
  • 仓库地址https://github.com/Valloric/YouCompleteMe

     入坑vim多天后逐步装插件对vim进行完善,终于今天开始尝试装最牛插件之一YouCompleteMe。一路也是遇到不少问题,甚至想从源码编译,最后发现其实都是些小问题。

本系统为ubuntu

先上插件网址:https://github.com/Valloric/YouCompleteMe

1、

请确保有以下依赖

sudo apt install build-essential cmake python3-dev

2、

这里用的是 vim-plug 下载,用vundle也差不多

  1. call plug#begin('~/.vim/plugged')
  2. Plug 'Valloric/YouCompleteMe', { 'do': './install.py --clang-completer'}
  3. call plug#end()

然后漫长等待至下好,这个时候并不是结束,而是才刚刚开始

3、

cd ~/.vim/plugged/YouCompleteMe/              (就是找到安装目录)

一般这个时候都没有完整克隆下来的,执行命令

git submodule update --init --recursive

好像就可以完整安装下来

4、本文章的重点之一,就是这里开始遇到问题的

在YouCompleteMe目录下运行编译安装

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

然后就惊奇发现终端有如下回复

CMake Error: The source directory "/home/rivalak/.cache/vimfiles/repos/github.com/Valloric/YouCompleteMe/third_party/ycmd/third_party/cregex" does not appear to contain CMakeLists.txt.

其实这是因为 ~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/cregex/ 的内部文件没有clone下来

解决方案:rm -rf ~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/cregex    (即删除掉)

                   再运行git submodule update --init --recursive

然后就可以  ./install.py --clang-completer  成功编译了

5、

然后是问题2:

打开vim,发现YouCompleteme unavailable : no module named future

原因是 ~/.vim/plugged/YouCompleteMe/third_party/python-future/ 的内部文件没有clone下来

解决方案:rm -rf ~/.vim/plugged/YouCompleteMe/third_party/python-future/

                   再运行git submodule update --init --recursive

                   然后  ./install.py --clang-completer  再编译

6、

然后是问题3:

当你认为终于搞定了高兴的用vim打开.c文件,然后发现

No .ycm_extra_conf.py file detected, so no compile flags are available. Thus no semantic support for C/C++/ObjC/ObjC++. Go READ THE DOCS NOW, DON'T file a bug report.

居然对c和c++不能用!!!

莫方,看英文,是因为找不到.ycm_extra_conf.py 这个文件

所以解决方法上:发现这个文件在   ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/  中,先用命令

mv ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/

从而移动该文件到~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/ 中

然后打开  .vimrc  文件,加入

let g:ycm_global_ycm_extra_conf = ‘~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py’

然后就大工告成了。

 

最后附上一个小提示:遇到问题可以查找github的issues,里面有很多dalao的解决方案

 

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

  •  rm -rf YouCompleteMe/third_party/ycmd/third_party/cregex 
  •  git submodule update --init --recursive  at the dir of "YouCompleteMe/third_party/ycmd/third_party"

完美解决!

 

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 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'Xuyuanp/nerdtree-git-plugin'

Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/syntastic'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'jiangmiao/auto-pairs'
Plugin 'Valloric/YouCompleteMe'


Plugin 'tpope/vim-fugitive'
Plugin 'rstacruz/sparkup', {'rtp': '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/'}


" 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

" airline


"设置打开vim的时候默认打开目录树"
let g:nerdtree_tabs_open_on_console_startup=1
" 关闭NERDTree快捷键
map <C-t> :NERDTreeToggle<CR>

""当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let g:NERDTreeDirArrowExpandable = ''
let g:NERDTreeDirArrowCollapsible = ''
let NERDTreeAutoCenter=1
" 是否显示隐藏文件
let NERDTreeShowHidden=1
" 设置宽度
let NERDTreeWinSize=23

"let g:NERDTreeIndicatorMapCustom = {
"    \ "Modified"  : "✹",
"    \ "Staged"    : "✚",
"    \ "Untracked" : "✭",
"    \ "Renamed"   : "➜",
"    \ "Unmerged"  : "═",
"    \ "Deleted"   : "✖",
"    \ "Dirty"     : "✗",
"    \ "Clean"     : "✔︎",
"    \ "Ignored"   : "☒'",
"    \ "Unknown"   : "?"
"    \ }


"""""""""""""""""""""""""""""""""""""""
let g:airline_powerline_fonts = 1
set t_Co=256
set laststatus=2

" ycm
"let g:ycm_python_binary_path='/usr/bin/python'
let g:ycm_confirm_extra_conf=0

"let g:ycm_server_python_interpreter='/usr/bin/python'
"let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'

let g:ycm_confirm_extra_conf=0
"let g:clang_use_library=1
set completeopt-=preview

" 不显示开启vim时检查ycm_extra_conf文件的信息  
let g:ycm_confirm_extra_conf=0
" 开启基于tag的补全,可以在这之后添加需要的标签路径  
let g:ycm_collect_identifiers_from_tags_files=1
"注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"" 输入第2个字符开始补全
let g:ycm_min_num_of_chars_for_completion=2
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0

" " 开启语义补全
let g:ycm_seed_identifiers_with_syntax=1
" "在注释输入中也能补全
let g:ycm_complete_in_comments = 1
" "在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" " 设置在下面几种格式的文件上屏蔽ycm

let g:ycm_filetype_blacklist = {
      \ 'tagbar' : 1,
      \ 'nerdtree' : 1,
      \}


let g:ycm_key_list_select_completion = ['<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
" 修改对C函数的补全快捷键,默认是CTRL + space,修改为ALT + ;
let g:ycm_key_invoke_completion = '<M-;>'

"let g:ycm_add_preview_to_completeopt = 0
""let g:ycm_show_diagnostics_ui = 0
let g:ycm_server_log_level = 'info'
let g:ycm_min_num_identifier_candidate_chars = 2
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_key_invoke_completion = '<c-z>'
"set completeopt=menu,menuone

noremap <c-z> <NOP>
let g:ycm_semantic_triggers =  {
                        \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
                        \ 'cs,lua,javascript': ['re!\w{2}'],
                        \ }


synta on

set number
set cindent
set autoindent

set expandtab

set smarttab
" set mouse=a
set shiftwidth=4
set softtabstop=4
set hls
set bg=dark

 注意:补全c++头文件,或者c的头文件,需要在 .ycm_extra_conf.py 文件里修改 flags

flags = [

] 里面加上,下面

'-isystem',
'/usr/include',
'-isystem',
'/usr/include/c++/5.4.0',

 

posted on 2020-08-07 20:52  莫水千流  阅读(953)  评论(0编辑  收藏  举报