MyBlog/vim代码补全插件YouCompleteMe的自动化安装[转].md at master · SigalHu/MyBlog · GitHub 您所在的位置:网站首页 安装win95左上角一条杠 MyBlog/vim代码补全插件YouCompleteMe的自动化安装[转].md at master · SigalHu/MyBlog · GitHub

MyBlog/vim代码补全插件YouCompleteMe的自动化安装[转].md at master · SigalHu/MyBlog · GitHub

2023-04-30 09:07| 来源: 网络整理| 查看: 265

原文:Vim代码补全插件:YouCompleteMe

注意: 若遇到映射inoremap 导致键无法删除,可参考《关于vim在插入模式中Backspace键无法删除的问题[转]》解决。

1. 下载vim配置和插件安装附件

git clone https://github.com/13570248114/vim_for_linux

文件说明:

libclang3.3是YouCompleteMe的依赖库 vim包含各种插件 .vimrc是vim的配置文件 install.sh是安装脚本 readme.txt是安装说明

2. 详细阅读安装脚本

#!/bin/bash echo "安装将花费一定时间,请耐心等待直到安装完成^_^" echo "正在安装必备的软件^_^" if which apt-get >/dev/null; then sudo apt-get update -y vi sudo apt-get install -y vim ctags cscope build-essential cmake python-dev elif which yum >/dev/null; then sudo apt-get update -y vi sudo yum install -y gcc vim ctags cscope cmake gcc-c++ python-devel sudo yum groupinstall -y "Development Tools" fi sudo ln -s /usr/bin/ctags /usr/local/bin/ctags echo "正在编译安装libclang3.3,大约二十分钟..." cd ./libclang3.3 sudo chmod +x ./install.sh ./install.sh echo "libclang3.3安装完成。^_^" cd .. echo "正在拷贝vim的插件和配置文件..." rm -Rf ~/.vim* mkdir ~/.vim cp -R ./vim/* ~/.vim cp ./.vimrc ~/ echo "vim插件和配置文件拷贝完成^_^" echo "正在安装YouCompleteMe插件..." cd ~/.vim/bundle/YouCompleteMe sudo chmod +x ./install.sh sudo chmod +x ./third_party/ycmd/build.sh ./install.sh --clang-completer --system-libclang echo "YouCompleteMe安装完成" echo "安装成功^_^" 首先脚本会安装必要的软件,包括vim ctags cscope build-essential cmake Python-dev,如果已经安装可以注释这个部分。 然后编译安装libclang3.3,该库是YouCompleteMe需要的,也可以通过其他途径安装该库,比如在ubuntu下可以直接使用sudo apt-get install clang进行安装。如已经安装可注释该部分。 接着是vim插件和配置文件的拷贝,注意,这个操作会将原本的vim配置和插件全部删掉,请谨慎,如有特殊要求请自行复制。 进行YouCompleteMe的编译安装。

3. 效果图

4. 常用快捷键(仅限于附件对应的vim配置文件)

打开和关闭左边的目录窗口:F2 窗口切换: ctrl+w+方向键(支持h j k l) 打开右边的函数列表窗口:在普通模式下按tb 跳转到函数定义:在普通模式下按,jd(别忽略逗号),需要在.vimrc上加上: nnoremap jd :YcmCompleter GoToDefinitionElseDeclaration 光标跳转:上一个位置ctrl+o,下一个位置ctrl+i 代码注释:在普通模式下,cc(注释),cu(取消注释)

5. vim的配置文件

" ----------------------------------------------------------------------------- let g:iswindows = 0 let g:islinux = 0 if(has("win32") || has("win64") || has("win95") || has("win16")) let g:iswindows = 1 else let g:islinux = 1 endif " ----------------------------------------------------------------------------- " < 判断是终端还是 Gvim > " ----------------------------------------------------------------------------- if has("gui_running") let g:isGUI = 1 else let g:isGUI = 0 endif " ============================================================================= " > " ============================================================================= " ----------------------------------------------------------------------------- " < Windows Gvim 默认配置> 做了一点修改 " ----------------------------------------------------------------------------- if (g:iswindows && g:isGUI) source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim behave mswin set diffexpr=MyDiff() function MyDiff() let opt = '-a --binary ' if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 = v:fname_new if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif let arg3 = v:fname_out if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif let eq = '' if $VIMRUNTIME =~ ' ' if &sh =~ '\ ' . arg3 . eq endfunction endif " ----------------------------------------------------------------------------- " < Linux Gvim/Vim 默认配置> 做了一点修改 " ----------------------------------------------------------------------------- if g:islinux set hlsearch "高亮搜索 set incsearch "在输入要搜索的文字时,实时匹配 " Uncomment the following to have Vim jump to the last position when " reopening a file if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") " ============================================================================= " ----------------------------------------------------------------------------- " < Vundle 插件管理工具配置 > " ----------------------------------------------------------------------------- " 用于更方便的管理vim插件,具体用法参考 :h vundle 帮助 " Vundle工具安装方法为在终端输入如下命令 " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle " 如果想在 windows 安装就必需先安装 "git for window",可查阅网上资料 set nocompatible "禁用 Vi 兼容模式 filetype off "禁用文件类型侦测 if g:islinux set rtp+=~/.vim/bundle/vundle/ call vundle#rc() else set rtp+=$VIM/vimfiles/bundle/vundle/ call vundle#rc('$VIM/vimfiles/bundle/') endif " 使用Vundle来管理插件,这个必须要有。 Bundle 'gmarik/vundle' " 以下为要安装或更新的插件,不同仓库都有(具体书写规范请参考帮助) Bundle 'a.vim' Bundle 'Align' Bundle 'jiangmiao/auto-pairs' Bundle 'bufexplorer.zip' Bundle 'ccvext.vim' Bundle 'cSyntaxAfter' Bundle 'ctrlpvim/ctrlp.vim' Bundle 'mattn/emmet-vim' Bundle 'Yggdroot/indentLine' Bundle 'vim-javacompleteex' Bundle 'Mark--Karkat' Bundle 'scrooloose/nerdcommenter' Bundle 'scrooloose/nerdtree' Bundle 'Lokaltog/vim-powerline' Bundle 'repeat.vim' Bundle 'msanders/snipmate.vim' Bundle 'wesleyche/SrcExpl' Bundle 'std_c.zip' Bundle 'tpope/vim-surround' Bundle 'scrooloose/syntastic' Bundle 'majutsushi/tagbar' Bundle 'taglist.vim' Bundle 'TxtBrowser' Bundle 'ZoomWin' Bundle 'Valloric/YouCompleteMe' " ----------------------------------------------------------------------------- " < 编码配置 > " ----------------------------------------------------------------------------- " 注:使用utf-8格式后,软件与程序源码、文件路径不能有中文,否则报错 set encoding=utf-8 "设置gvim内部编码,默认不更改 set fileencoding=utf-8 "设置当前文件编码,可以更改,如:gbk(同cp936) set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1 "设置支持打开的文件的编码 " 文件格式,默认 ffs=dos,unix set fileformat=unix "设置新(当前)文件的格式,可以更改,如:dos(windows系统常用) set fileformats=unix,dos,mac "给出文件的格式类型 if (g:iswindows && g:isGUI) "解决菜单乱码 source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim "解决consle输出乱码 language messages zh_CN.utf-8 endif " ----------------------------------------------------------------------------- " < 编写文件时的配置 > " ----------------------------------------------------------------------------- filetype on "启用文件类型侦测 filetype plugin on "针对不同的文件类型加载对应的插件 filetype plugin indent on "启用缩进 set smartindent "启用智能对齐方式 set expandtab "将Tab键转换为空格 set tabstop=4 "设置Tab键的宽度,可以更改,如:宽度为2 set shiftwidth=4 "换行时自动缩进宽度,可更改(宽度同tabstop) set smarttab "指定按一次backspace就删除shiftwidth宽度 set foldenable "启用折叠 set foldmethod=indent "indent 折叠方式 set foldlevel=9999 " 折叠的层次,打开文件时默认不折叠 " 常规模式下用空格键来开关光标行所在折叠(注:zR 展开所有折叠,zM 关闭所有折叠) nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo') " 当文件在外部被修改,自动更新该文件 set autoread " 常规模式下输入 cS 清除行尾空格 nmap cS :%s/\s\+$//g:noh " 常规模式下输入 cM 清除行尾 ^M 符号 nmap cM :%s/\r$//g:noh set ignorecase "搜索模式里忽略大小写 set smartcase "如果搜索模式包含大写字符,不使用 'ignorecase' 选项,只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用 " set noincsearch "在输入要搜索的文字时,取消实时匹配 " Ctrl + K 插入模式下光标向上移动 imap " Ctrl + J 插入模式下光标向下移动 imap " Ctrl + H 插入模式下光标向左移动 imap " Ctrl + L 插入模式下光标向右移动 imap " Ctrl + f 光标跳转到行头 imap 0i " Ctrl + e 光标跳转到行尾 imap $i " 全选 nmap ggVG$ imap ggVG$ " 启用每行超过80列的字符提示(字体变蓝并加下划线),不启用就注释掉 au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1) " ----------------------------------------------------------------------------- " < 界面配置 > " ----------------------------------------------------------------------------- set number "显示行号 set laststatus=2 "启用状态栏信息 set cmdheight=2 "设置命令行的高度为2,默认为1 set cursorline "突出显示当前行 " set guifont=YaHei_Consolas_Hybrid:h10 "设置字体:字号(字体名称空格用下划线代替) set nowrap "设置不自动换行 set shortmess=atI "去掉欢迎界面 " 设置 gVim 窗口初始位置及大小 if g:isGUI " au GUIEnter * simalt ~x "窗口启动时自动最大化 winpos 100 10 "指定窗口出现的位置,坐标原点在屏幕左上角 set lines=38 columns=120 "指定窗口大小,lines为高度,columns为宽度 endif " 设置代码配色方案 if g:isGUI colorscheme Tomorrow-Night-Eighties "Gvim配色方案 else colorscheme Tomorrow-Night-Eighties "终端配色方案 endif " 显示/隐藏菜单栏、工具栏、滚动条,可用 Ctrl + F11 切换 if g:isGUI set guioptions-=m set guioptions-=T set guioptions-=r set guioptions-=L nmap :if &guioptions =~# 'm' \set guioptions-=m \set guioptions-=T \set guioptions-=r \set guioptions-=L \else \set guioptions+=m \set guioptions+=T \set guioptions+=r \set guioptions+=L \endif endif " ----------------------------------------------------------------------------- " < 编译、连接、运行配置 (目前只配置了C、C++、Java语言)> " ----------------------------------------------------------------------------- " F5 一键保存、编译、连接存并运行 nmap :call Run() imap :call Run() " Ctrl + F5 一键保存并编译 nmap :call Compile() imap :call Compile() "C,C++的调试 map :call Rungdb() imap :call Rungdb() " Ctrl + F6 一键保存并连接 nmap :call Link() imap :call Link() let s:LastShellReturn_C = 0 let s:LastShellReturn_L = 0 let s:ShowWarning = 1 let s:Obj_Extension = '.o' let s:Exe_Extension = '.exe' let s:Class_Extension = '.class' let s:Sou_Error = 0 let s:windows_CFlags = 'gcc\ -fexec-\ -Wall\ -g\ -O0\ -c\ %\ -o\ % ' . arg3 . eq endfunction endif " ----------------------------------------------------------------------------- " < Linux Gvim/Vim 默认配置> 做了一点修改 " ----------------------------------------------------------------------------- if g:islinux set hlsearch "高亮搜索 set incsearch "在输入要搜索的文字时,实时匹配 " Uncomment the following to have Vim jump to the last position when " reopening a file if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") " ============================================================================= " ----------------------------------------------------------------------------- " < Vundle 插件管理工具配置 > " ----------------------------------------------------------------------------- " 用于更方便的管理vim插件,具体用法参考 :h vundle 帮助 " Vundle工具安装方法为在终端输入如下命令 " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle " 如果想在 windows 安装就必需先安装 "git for window",可查阅网上资料 set nocompatible "禁用 Vi 兼容模式 filetype off "禁用文件类型侦测 if g:islinux set rtp+=~/.vim/bundle/vundle/ call vundle#rc() else set rtp+=$VIM/vimfiles/bundle/vundle/ call vundle#rc('$VIM/vimfiles/bundle/') endif " 使用Vundle来管理插件,这个必须要有。 Bundle 'gmarik/vundle' " 以下为要安装或更新的插件,不同仓库都有(具体书写规范请参考帮助) Bundle 'a.vim' Bundle 'Align' Bundle 'jiangmiao/auto-pairs' Bundle 'bufexplorer.zip' Bundle 'ccvext.vim' Bundle 'cSyntaxAfter' Bundle 'ctrlpvim/ctrlp.vim' Bundle 'mattn/emmet-vim' Bundle 'Yggdroot/indentLine' Bundle 'vim-javacompleteex' Bundle 'Mark--Karkat' Bundle 'scrooloose/nerdcommenter' Bundle 'scrooloose/nerdtree' Bundle 'Lokaltog/vim-powerline' Bundle 'repeat.vim' Bundle 'msanders/snipmate.vim' Bundle 'wesleyche/SrcExpl' Bundle 'std_c.zip' Bundle 'tpope/vim-surround' Bundle 'scrooloose/syntastic' Bundle 'majutsushi/tagbar' Bundle 'taglist.vim' Bundle 'TxtBrowser' Bundle 'ZoomWin' Bundle 'Valloric/YouCompleteMe' " ----------------------------------------------------------------------------- " < 编码配置 > " ----------------------------------------------------------------------------- " 注:使用utf-8格式后,软件与程序源码、文件路径不能有中文,否则报错 set encoding=utf-8 "设置gvim内部编码,默认不更改 set fileencoding=utf-8 "设置当前文件编码,可以更改,如:gbk(同cp936) set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1 "设置支持打开的文件的编码 " 文件格式,默认 ffs=dos,unix set fileformat=unix "设置新(当前)文件的格式,可以更改,如:dos(windows系统常用) set fileformats=unix,dos,mac "给出文件的格式类型 if (g:iswindows && g:isGUI) "解决菜单乱码 source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim "解决consle输出乱码 language messages zh_CN.utf-8 endif " ----------------------------------------------------------------------------- " < 编写文件时的配置 > " ----------------------------------------------------------------------------- filetype on "启用文件类型侦测 filetype plugin on "针对不同的文件类型加载对应的插件 filetype plugin indent on "启用缩进 set smartindent "启用智能对齐方式 set expandtab "将Tab键转换为空格 set tabstop=4 "设置Tab键的宽度,可以更改,如:宽度为2 set shiftwidth=4 "换行时自动缩进宽度,可更改(宽度同tabstop) set smarttab "指定按一次backspace就删除shiftwidth宽度 set foldenable "启用折叠 set foldmethod=indent "indent 折叠方式 set foldlevel=9999 " 折叠的层次,打开文件时默认不折叠 " 常规模式下用空格键来开关光标行所在折叠(注:zR 展开所有折叠,zM 关闭所有折叠) nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo') " 当文件在外部被修改,自动更新该文件 set autoread " 常规模式下输入 cS 清除行尾空格 nmap cS :%s/\s\+$//g:noh " 常规模式下输入 cM 清除行尾 ^M 符号 nmap cM :%s/\r$//g:noh set ignorecase "搜索模式里忽略大小写 set smartcase "如果搜索模式包含大写字符,不使用 'ignorecase' 选项,只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用 " set noincsearch "在输入要搜索的文字时,取消实时匹配 " Ctrl + K 插入模式下光标向上移动 imap " Ctrl + J 插入模式下光标向下移动 imap " Ctrl + H 插入模式下光标向左移动 imap " Ctrl + L 插入模式下光标向右移动 imap " Ctrl + f 光标跳转到行头 imap 0i " Ctrl + e 光标跳转到行尾 imap $i " 全选 nmap ggVG$ imap ggVG$ " 启用每行超过80列的字符提示(字体变蓝并加下划线),不启用就注释掉 au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1) " ----------------------------------------------------------------------------- " < 界面配置 > " ----------------------------------------------------------------------------- set number "显示行号 set laststatus=2 "启用状态栏信息 set cmdheight=2 "设置命令行的高度为2,默认为1 set cursorline "突出显示当前行 " set guifont=YaHei_Consolas_Hybrid:h10 "设置字体:字号(字体名称空格用下划线代替) set nowrap "设置不自动换行 set shortmess=atI "去掉欢迎界面 " 设置 gVim 窗口初始位置及大小 if g:isGUI " au GUIEnter * simalt ~x "窗口启动时自动最大化 winpos 100 10 "指定窗口出现的位置,坐标原点在屏幕左上角 set lines=38 columns=120 "指定窗口大小,lines为高度,columns为宽度 endif " 设置代码配色方案 if g:isGUI colorscheme Tomorrow-Night-Eighties "Gvim配色方案 else colorscheme Tomorrow-Night-Eighties "终端配色方案 endif " 显示/隐藏菜单栏、工具栏、滚动条,可用 Ctrl + F11 切换 if g:isGUI set guioptions-=m set guioptions-=T set guioptions-=r set guioptions-=L nmap :if &guioptions =~# 'm' \set guioptions-=m \set guioptions-=T \set guioptions-=r \set guioptions-=L \else \set guioptions+=m \set guioptions+=T \set guioptions+=r \set guioptions+=L \endif endif " ----------------------------------------------------------------------------- " < 编译、连接、运行配置 (目前只配置了C、C++、Java语言)> " ----------------------------------------------------------------------------- " F5 一键保存、编译、连接存并运行 nmap :call Run() imap :call Run() " Ctrl + F5 一键保存并编译 nmap :call Compile() imap :call Compile() "C,C++的调试 map :call Rungdb() imap :call Rungdb() " Ctrl + F6 一键保存并连接 nmap :call Link() imap :call Link() let s:LastShellReturn_C = 0 let s:LastShellReturn_L = 0 let s:ShowWarning = 1 let s:Obj_Extension = '.o' let s:Exe_Extension = '.exe' let s:Class_Extension = '.class' let s:Sou_Error = 0 let s:windows_CFlags = 'gcc\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有