????????先放上已打造好、可直接使用的VIM-IDE包,懒得一步一步操作配置的可直接下载解压后使用。
Ubuntu 64位免安装版VIM-IDE。 压缩包为直接打包/etc/vim配置及插件包
https://download.csdn.net/download/qq_25145163/20550802
window 32位 VIM-IDE
基于win32版本vim82搭建IDE,解压文件到自定义目录下即可,并设置系统环境变量VIM 值为该目录
https://download.csdn.net/download/qq_25145163/20552884?
? ? ? ? 接下来,转入正题,下面将详细介绍操作步骤:?
前期准备
????????需要安装git、cscope工具,可通过apt-get 自行安装
???apt-get install cscope git
安装插件管理工具Vundle(必备)
git?clone?https://github.com/VundleVim/Vundle.vim.git? /etc/vim/bundle/Vundle.vim
? ? ? ? 虽然仅占用空间 1.4M,?但从github.com 上clone速度会稍慢点,因此不要着急
配置插件
????????在/etc/vim下找到vimrc,在文件最后加入以下内容,用来支持插件的配置文件?/etc/vim/vimrc.Vundle
set fileencodings=utf-8,gbk,gb2312,gb18030
set fileencoding=utf8
set encoding=utf8
set nu
if filereadable("/etc/vim/vimrc.Vundle")
source /etc/vim/vimrc.Vundle
endif
? ? ? ?具体的配置文件如下,相关配置的介绍资料有很多,此处不再赘述,该文件中已包含大部分常用的插件的配置。
"
" ==============vim基本配置==============
set guifont=Monospace\ 14
set nu " 显示行号
syntax enable
syntax on
colorscheme desert
set path+="/usr/include,../include"
set autowrite " 自动保存
set autoindent "自动对齐
set foldmethod=syntax
set foldlevel=100 " 启动vim时不要自动折叠代码
set textwidth=80
set formatoptions+=t
set cindent "使用 C/C++ 语言的自动缩进方式
set smartindent "智能对齐
set noerrorbells
set showmatch "高亮显示对应的括号
set nobackup
set noswapfile
"set cursorline "突出显示当前行
set incsearch "搜素高亮,搜索逐渐高亮
set hlsearch "高亮度搜寻
" disable
"noremap <Up> <Nop>
"noremap <Down> <Nop>
"noremap <Left> <Nop>
"noremap <Right> <Nop>
" remap control + arrow key to select windows
noremap <C-Down> <C-W>j
noremap <C-Up> <C-W>k
noremap <C-Left> <C-W>h
noremap <C-Right> <C-W>l
noremap <C-J> <C-W>j
noremap <C-K> <C-W>k
noremap <C-H> <C-W>h
noremap <C-L> <C-W>l
" ==============Vundle插件管理==============
" Vundle manage
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=$VIM/vimfiles/bundle/Vundle.vim
call vundle#rc('$VIM/vimfiles/bundle/')
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe' "代码补齐
Plugin 'SirVer/ultisnips' "代码块补全
Plugin 'honza/vim-snippets'
Plugin 'ervandew/supertab' "解决多个插件共用TAB键问题
Plugin 'scrooloose/nerdtree' "目录树
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'jistr/vim-nerdtree-tabs'
"Plugin 'majutsushi/tagbar' " Tag bar
Plugin 'vim-airline/vim-airline' | Plugin 'vim-airline/vim-airline-themes' " Status line"
Plugin 'Lokaltog/vim-powerline'
Plugin 'jiangmiao/auto-pairs' "自动成对操作括号
Plugin 'mbbill/undotree' "撤销修改
Plugin 'gdbmgr' "调试器插件
Plugin 'scrooloose/nerdcommenter' "快速注释/反注释插件
Plugin 'Yggdroot/indentLine' "对齐线
Plugin 'bling/vim-bufferline' " Buffer line
Plugin 'kepbod/quick-scope' " Quick scope
Plugin 'yianwillis/vimcdoc' "vim中文帮助文档
Plugin 'nelstrom/vim-visual-star-search'
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'w0rp/ale'
Plugin 'mbbill/echofunc' "自动显示函数声明插件
Plugin 'Yggdroot/LeaderF', { 'do': './install.sh' } "文件、buffers、mrus(most recently used)、tags 的检索
"All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" ===========supertab============
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'
let g:SuperTabRetainCompletionType=2
" better key bindings for UltiSnipsExpandTrigger
"let g:UltiSnipsExpandTrigger="<c-e>"
"let g:UltiSnipsJumpForwardTrigger="<c-j>"
"let g:UltiSnipsJumpBackwardTrigger="<c-k>"
" ==============YCM==============
let g:ycm_server_python_interpreter='/usr/bin/python'
let g:ycm_global_ycm_extra_conf='$VIM/vimfiles/.ycm_extra_conf.py'
" 停止提示是否载入本地ycm_extra_conf文件
let g:ycm_confirm_extra_conf = 0
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax = 1
" 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_tags_files = 1
" 从第2个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2
" 在注释输入中也能补全
let g:ycm_complete_in_comments = 1
" 在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" 注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1
" YCM 查找定义
let mapleader=','
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
let g:ycm_collect_identifiers_from_tags_files = 1
set completeopt=menu,menuone
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_complete_in_strings=1
noremap <c-z> <NOP>
let g:ycm_key_invoke_completion = '<c-z>' " YCM 里触发语义补全有一个快捷键
let g:ycm_max_num_candidates = 15 " 候选数量
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}'],
\ }
"==========设置代码块补全==========
let g:UltiSnipsExpandTrigger="<tab>" "被代码补齐占用
"let g:UltiSnipsExpandTrigger="<c-z>"
let g:UltiSnipsJumpForwardTrigger="<c-h>"
let g:UltiSnipsJumpBackwardTrigger="<c-l>"
" ===========gutentags=============
"let g:gutentags_enabled='0'
"let g:gutentags_trace = '1'
" 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project', '.gitignore']
" 添加ctags额外参数,会让tags文件变大
" let g:gutentags_ctags_extra_args = ['--fields=+niazlS', '--extra=+q']
let g:gutentags_ctags_extra_args = ['--fields=+lS']
let g:gutentags_ctags_extra_args += ['--languages=c,c++']
" let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
"let g:gutentags_cache_dir = expand('~/.cache/tags')
"let g:gutentags_ctags_tagfile=".tags"
if isdirectory("kernel/") && isdirectory("mm/")
let g:gutentags_file_list_command = 'find arch/arm/ mm/ kernel/ include/ init/ lib/ drivers/'
endif
" =======echodoc 显示函数参数===========
"let g:EchoFuncShowOnStatus = 0
"ctags -R --fields=+lS .
"======= NerdTree=========
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
let NERDTreeWinSize=30
"显示行号
let NERDTreeShowLineNumbers=1
let NERDTreeAutoCenter=1
"使用书签功能
let NERDTreeShowBookmarks=1
let g:winManagerWindowLayout='TagList'
nmap wm :WMToggle<cr>
"设置F3触发
map <F3> :NERDTreeToggle<CR>
"自动关闭树形目录
let NERDTreeQuitOnOpen = 1
"高亮当前行
let NERDTreeHighlightCursorline = 1
"是否显示隐藏文件
let g:NERDTreeShowHidden = 0
"忽略特定文件和目录
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.py\$class$', '\.obj$',
\ '\.o$', '\.so$', '\.egg$', '^\.git$', '__pycache__', '\.DS_Store' ]
"======nerdtree-git-plugin===
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "?",
\ "Staged" : "?",
\ "Untracked" : "?",
\ "Renamed" : "?",
\ "Unmerged" : "═",
\ "Deleted" : "?",
\ "Dirty" : "?",
\ "Clean" : "??",
\ "Unknown" : "?"
\ }
"--------------------------------------------------------------------------------
" 自动加载ctags: ctags -R
if filereadable("tags")
set tags=tags
endif
"if filereadable(".tags")
" set tags=.tags
"endif
"--------------------------------------------------------------------------------
" cscope:建立数据库:cscope -Rbq; F5 查找c符号; F6 查找字符串; F7 查找函数定义; F8 查找函数谁调用了,
"--------------------------------------------------------------------------------
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
:set cscopequickfix=s-,c-,d-,i-,t-,e-
nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>
"nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
"F5 查找c符号; F6 查找字符串; F7 查找函数定义; F8 查找函数谁调用了,
nmap <silent> <F5> :cs find s <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
nmap <silent> <F6> :cs find t <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
"nmap <silent> <F7> :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <silent> <F7> :cs find c <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
"--------------------------------------------------------------------------------
" global:建立数据库
"--------------------------------------------------------------------------------
if filereadable("GTAGS")
set cscopetag
set cscopeprg=gtags-cscope
cs add GTAGS
au BufWritePost *.c,*.cpp,*.h silent! !global -u &
endif
" ======ALE静态语法检测========
let g:ale_sign_column_always = 1
let g:ale_sign_error = '?'
let g:ale_sign_warning = 'w'
let g:ale_statusline_format = ['? %d', '? %d', '? OK']
let g:ale_echo_msg_format = '[%linter%] %code: %%s'
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
"let g:airline#extensions#ale#enabled = 1
let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14'
let g:ale_c_cppcheck_options = ''
let g:ale_cpp_cppcheck_options = ''
"增加使用make -n 来更好的解决误报错问题(误报头文件等)
let g:ale_c_parse_makefile=1
"普通模式下,sp前往上一个错误或警告,sn前往下一个错误或警告
nmap sp <Plug>(ale_previous_wrap)
nmap sn <Plug>(ale_next_wrap)
"<Leader>s触发/关闭语法检查
nmap <Leader>s :ALEToggle<CR>
"<Leader>d查看错误或警告的详细信息
nmap <Leader>d :ALEDetail<CR>
" ========airline状态栏=========
let g:airline_section_b = '%-0.10{getcwd()}'
let g:airline_section_c = '%t'
let g:airline#extensions#tagbar#enabled = 1
let g:airline_section_y = ''
set t_Co=256 "在windows中用xshell连接打开vim可以显示色彩
"set nocompatible " Disable vi-compatibility
" 总是显示状态栏
set laststatus=2 " Always show the statusline
"set encoding=utf-8 " Necessary to show Unicode glyphs
"解决consle输出乱码
"set termencoding = cp936
"设置中文提示
language messages zh_CN.utf-8
"设置中文帮助
set helplang=cn
" 设置为双字宽显示,否则无法完整显示如:☆
set ambiwidth=double
let g:airline_powerline_fonts = 1 " 使用powerline打过补丁的字体
let g:Powerline_symbols= 'unicode'
let g:airline_theme="dark" " 设置主题
"let g:airline_theme="luna"
"let g:airline_theme='bubblegum'
"打开tabline功能,方便查看Buffer和切换,这个功能比较不错"
"我还省去了minibufexpl插件,因为我习惯在1个Tab下用多个buffer"
let g:airline#extensions#tabline#enabled = 1
"tabline中当前buffer两端的分隔字符
let g:airline#extensions#tabline#left_sep = '┇'
"tabline中未激活buffer两端的分隔字符
let g:airline#extensions#tabline#left_alt_sep = '|'
"tabline中buffer显示编号
let g:airline#extensions#tabline#buffer_nr_show = 1
"let g:airline#extensions#tabline#buffer_nr_format = "[%s]"
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" unicode symbols
let g:airline_left_sep = '? '
let g:airline_right_sep = '? '
let g:airline_symbols.crypt = '🔒'
let g:airline_symbols.linenr = '?'
"let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.maxlinenr = '㏑'
let g:airline_symbols.branch = '?'
let g:airline_symbols.paste = 'ρ '
let g:airline_symbols.spell = '?'
let g:airline_symbols.notexists = '?'
let g:airline_symbols.whitespace = 'Ξ '
"设置切换Buffer快捷键"
nnoremap <C-N> :bn<CR>
nnoremap <C-P> :bp<CR>
? ? ? ? 以上是本人自用的插件管理配置文件,浏览该配置文件可知,其主要包涵三大部分,vim基本配置、插件管理部分、具体插件配置项。
? ? ? ? vim基本配置部分,主要是用来配置一些基本的vim基本的配置项,方便使用。
????????插件管理部分,主要包含两块,一是指定插件管理工具Vundle的路径(set rtp+=$VIM/vimfiles/bundle/Vundle.vim),二是管理插件,如需新增插件,只需在call vundle#begin()与?call vundle#end()之间加入插件即可,格式为?Plugin+插件 (如Plugin 'Valloric/YouCompleteMe')。
? ? ? ? 具体插件配置项是对加载的插件进行配置,如下图为自动补全插件的配置。
?加载插件
?执行 vim
?输入 :PluginInstall
回车,此时可以歇会了,Vundle会按顺序下载配置中的插件
????????插件下载完成后,可在/etc/vim/bundle下查看到下载的内容。
?????????如因网络原因导致下载失败,可以多执行几次?:PluginInstall。
?处理插件
?配置自动补全插件YCM?
????????此插件要求vim版本必须高于7.4.1578,ubuntu1804自带vim
- ?之前已在.vimrc中配置了Plugin 'Valloric/YouCompleteMe',则会自动下载插件,下载位置是/etc/vim/bundle/YouCompleteMe
- 编译前准备 YouCompleteMe编译需要以下根据的支持:?build-essential cmake python-dev python3-dev
- 代码编译
????????./install.py --clang-completer;
????????????????--clang-completer:表示支持C/C++的支持;
?????????如果是使用系统的libclang-9.so的话,还要增加参数 --system-libclang,这样的话,不用每次执行该命令都要下载库。
????????4.?配置YCM
????????cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py? /etc/vim/
? ? ? ?多项目配置问题
????????上述步骤4以可以完成基本使用,但在实际使用中,存在一个用户拥有多个工程,而每个工程的配置不尽相同的问题。此时可以在每个工程下建立一个.ycm_extra_conf.py文件,每个工程默认读取自己的配置。
因为YCM配置文件的查找顺序是当前目录>上层目录>...>根目录>YCM全局目录,所以这样的操作是没有问题的,但会出现每次打开vim就会提示是否载入YCM配置文件。此时需修改
let g:ycm_confirm_extra_conf = 0
?插件效果
|