ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

安装YCM

2021-05-20 10:33:25  阅读:262  来源: 互联网

标签:set YCM compilation vim flags ycm filename 安装


安装Vundle

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

Vundle也是vim的插件,所以放到~/.vim/bundle/下。

安装环境

# install CMake
sudo apt-get install build-essential cmake
# install Python
sudo apt-get install python-dev python3-dev

配置.vimrc

"set mouse=a
"set paste  "取消自动注释
set selection=exclusive
set selectmode=mouse,key
set number
set tabstop=4 
set softtabstop=4 
set shiftwidth=4 
set noexpandtab 
set relativenumber number  
set autoindent
set cindent

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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()
"
Plugin 'VundleVim/Vundle.vim'
Plugin 'https://gitee.com/mirrors/youcompleteme.git' 
 "这个就是YCM插件
call vundle#end()            " required
filetype plugin indent on    " required
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:ycm_server_python_interpreter='/usr/bin/python3'
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
let g:ycm_key_invoke_completion = '<c-z>'
let g:ycm_semantic_triggers =  {
                        \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
                        \ 'cs,lua,javascript': ['re!\w{2}'],
                        \ }
let g:ycm_confirm_extra_conf = 1 "设置为0关闭加载提示
let g:ycm_autoclose_preview_window_after_completion = 1 " 关闭原型提示
let g:ycm_autoclose_preview_window_after_insertion = 1 
"let g:ycm_key_list_select_completion = ['<C-o>', '<C-l>']
let g:ycm_show_diagnostics_ui = 0   "关闭语法诊断

然后运行:PluginInstall,等待安装完成。

然后编译YCM

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

最后在项目目录下新建.ycm_extra_conf.py

import os
import ycm_core

flags = [ 
'-Wall',
'-Wextra',
'-Werror',
'-fexceptions',
'-DNDEBUG',

'-std=c++11',

'-x',
'c++',
'-isystem',
'/usr/include',
'-isystem',
'/usr/local/include',
'-isystem',
'/usr/include/c++/9',  这里要改!系统的c++头文件目录
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include',
]

compilation_database_folder = ''

if os.path.exists( compilation_database_folder ):
  database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
  database = None

SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]

def DirectoryOfThisScript():
  return os.path.dirname( os.path.abspath( __file__ ) )

def IsHeaderFile( filename ):
  extension = os.path.splitext( filename )[ 1 ]
  return extension in [ '.h', '.hxx', '.hpp', '.hh' ]

def GetCompilationInfoForFile( filename ):
  # The compilation_commands.json file generated by CMake does not have entries
  # for header files. So we do our best by asking the db for flags for a
  # corresponding source file, if any. If one exists, the flags for that file
  # should be good enough.
  if IsHeaderFile( filename ):
    basename = os.path.splitext( filename )[ 0 ]
    for extension in SOURCE_EXTENSIONS:
      replacement_file = basename + extension
      if os.path.exists( replacement_file ):
        compilation_info = database.GetCompilationInfoForFile(
          replacement_file )
        if compilation_info.compiler_flags_:
          return compilation_info
    return None
  return database.GetCompilationInfoForFile( filename )


# This is the entry point; this function is called by ycmd to produce flags for
# a file.
def Settings( **kwargs ):
	if not database::
		return {
            'flags': flags,
            'include_paths_relative_to_dir': DirectoryOfThisScript()
        }
    filename = kwargs[ 'filename' ]
    compilation_info = GetCompilationInfoForFile( filename )
    if not compilation_info:
        return None

  # Bear in mind that compilation_info.compiler_flags_ does NOT return a
  # python list, but a "list-like" StringVec object.
    return {
        'flags': list( compilation_info.compiler_flags_ ),
        'include_paths_relative_to_dir': compilation_info.compiler_working_dir_
    }

中文帮助手册

PS

学到一点新东西

inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"

i:插入状态下有效

nore:不递归

map:按键映射

:表示被代替按键是个表达式

pumvisible():Returns non-zero when the popup menu is visible, zero otherwise. See ins-completion-menu.This can be used to avoid some things that would remove the popup menu.

大概意思就是vim弹出选择菜单时返回非0值,这时候按就是,ctrl+n:向下选择,否则就是

标签:set,YCM,compilation,vim,flags,ycm,filename,安装
来源: https://www.cnblogs.com/rookiezjz/p/14788796.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有