zoukankan      html  css  js  c++  java
  • vim配置

    说明

    本文参考两种配置方法,自测都可以配置成功。配置二的vim使用上不太会,因此,实际使用的是配置一。

    配置一

    参考笨书书的“把vim打造比Source insight更好用更强大的IDE.pdf”

    步骤

    (1)安装工具

    //安装插件管理工具 vundle
    git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
    //安装编译插件需要的软件包
    sudo apt-get install build-essential cmake python-dev python3-dev
    //安装ctags, cscope
    sudo apt-get install ctags
    sudo apt-get install cscope

    (2)创建 ~/.vimrc

      1 " ==============vim基本配置==============
      2 set guifont=Monospace 14
      3 set nu!             " 显示行号
      4 syntax enable
      5 syntax on
      6 colorscheme desert
      7 
      8 set autowrite   " 自动保存
      9 
     10 set foldmethod=syntax
     11 set foldlevel=100  " 启动vim时不要自动折叠代码
     12 set textwidth=80
     13 set formatoptions+=t
     14 set cindent
     15 set smartindent
     16 set noerrorbells
     17 set showmatch
     18 set nobackup
     19 set noswapfile
     20 " set cursorline
     21 
     22 " disable
     23 noremap <Up> <Nop>
     24 noremap <Down> <Nop>
     25 noremap <Left> <Nop>
     26 noremap <Right> <Nop>
     27 
     28 " remap control + arrow key to select windows
     29 noremap <C-Down>  <C-W>j
     30 noremap <C-Up>    <C-W>k
     31 noremap <C-Left>  <C-W>h
     32 noremap <C-Right> <C-W>l
     33 noremap <C-J> <C-W>j
     34 noremap <C-K> <C-W>k
     35 noremap <C-H> <C-W>h
     36 noremap <C-L> <C-W>l
     37 
     38 " ==============Vundle插件管理==============
     39 " Vundle manage
     40 set nocompatible              " be iMproved, required
     41 filetype off                  " required
     42 
     43 " set the runtime path to include Vundle and initialize
     44 set rtp+=~/.vim/bundle/Vundle.vim
     45 call vundle#begin()
     46 
     47 " let Vundle manage Vundle, required
     48 Plugin 'VundleVim/Vundle.vim'
     49 Plugin 'scrooloose/nerdtree'
     50 " Plugin 'majutsushi/tagbar' " Tag bar"
     51 Plugin 'Xuyuanp/nerdtree-git-plugin'
     52 Plugin 'jistr/vim-nerdtree-tabs'
     53 Plugin 'vim-airline/vim-airline' | Plugin 'vim-airline/vim-airline-themes' " Status line"
     54 Plugin 'jiangmiao/auto-pairs'
     55 Plugin 'mbbill/undotree'
     56 Plugin 'gdbmgr'
     57 Plugin 'scrooloose/nerdcommenter'
     58 Plugin 'Yggdroot/indentLine' " Indentation level"
     59 Plugin 'bling/vim-bufferline' " Buffer line"
     60 "Plugin 'kepbod/quick-scope' " Quick scope
     61 Plugin 'yianwillis/vimcdoc'
     62 Plugin 'nelstrom/vim-visual-star-search'
     63 Plugin 'ludovicchabant/vim-gutentags'
     64 Plugin 'w0rp/ale'
     65 Plugin 'mbbill/echofunc'
     66 Plugin 'Yggdroot/LeaderF', { 'do': './install.sh' }
     67 Plugin 'Valloric/YouCompleteMe'
     68 Plugin 'majutsushi/tagbar'
     69 
     70 " All of your Plugins must be added before the following line
     71 call vundle#end()            " required
     72 filetype plugin indent on    " required
     73 
     74 
     75 " ==============YCM==============
     76 let g:ycm_server_python_interpreter='/usr/bin/python'
     77 let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
     78   " YCM 查找定义
     79 let mapleader=','
     80 nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
     81 nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
     82 nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
     83 let g:ycm_collect_identifiers_from_tags_files = 1
     84 
     85 set completeopt=menu,menuone
     86 let g:ycm_add_preview_to_completeopt = 0  " 关闭函数原型提示
     87 
     88 let g:ycm_show_diagnostics_ui = 0 " 关闭诊断信息
     89 let g:ycm_server_log_level = 'info'
     90 let g:ycm_min_num_identifier_candidate_chars = 2  " 两个字符触发 补全
     91 let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 收集
     92 let g:ycm_complete_in_strings=1
     93 let g:ycm_server_python_interpreter='/usr/bin/python'
     94 let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
     95 
     96 noremap <c-z> <NOP>
     97 let g:ycm_key_invoke_completion = '<c-z>'   " YCM 里触发语义补全有一个快捷键
     98 let g:ycm_max_num_candidates = 15  " 候选数量
     99 
    100 let g:ycm_semantic_triggers =  {
    101              'c,cpp,python,java,go,erlang,perl': ['re!w{2}'],
    102              'cs,lua,javascript': ['re!w{2}'],
    103              }
    104 
    105 
    106 " ===========gutentags=============
    107 " 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
    108 let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project', '.gitignore']
    109 
    110 " 添加ctags额外参数,会让tags文件变大
    111 " let g:gutentags_ctags_extra_args = ['--fields=+niazlS', '--extra=+q']
    112  let g:gutentags_ctags_extra_args = ['--fields=+lS']
    113 " let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
    114 " let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
    115 
    116 if isdirectory("kernel/") && isdirectory("mm/")
    117     let g:gutentags_file_list_command = 'find arch/arm/ mm/ kernel/ include/ init/ lib/'
    118 endif
    119 
    120 
    121 " =======echodoc 显示函数参数===========
    122 " ctags -R --fields=+lS .
    123 
    124 "======= NetRedTree=========
    125 autocmd StdinReadPre * let s:std_in=1
    126 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
    127 let NERDTreeWinSize=20
    128 "let NERDTreeShowLineNumbers=1
    129 let NERDTreeAutoCenter=1
    130 let NERDTreeShowBookmarks=1
    131 
    132 let g:winManagerWindowLayout='TagList'
    133 nmap wm :WMToggle<cr>
    134 
    135 " ======ALE静态语法检测========
    136 let g:ale_sign_column_always = 1
    137 let g:ale_sign_error = ''
    138 let g:ale_sign_warning = 'w'
    139 let g:ale_statusline_format = ['✗ %d', '⚡ %d', '✔ OK']
    140 let g:ale_echo_msg_format = '[%linter%] %code: %%s'
    141 let g:ale_lint_on_text_changed = 'normal'
    142 let g:ale_lint_on_insert_leave = 1
    143 "let g:airline#extensions#ale#enabled = 1
    144 let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
    145 let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14'
    146 let g:ale_c_cppcheck_options = ''
    147 let g:ale_cpp_cppcheck_options = ''
    148 
    149 " ========airline状态栏=========
    150 let g:airline#extensions#tabline#enabled = 1
    151 let g:airline_section_b = '%-0.10{getcwd()}'
    152 let g:airline_section_c = '%t'
    153 let g:airline#extensions#tagbar#enabled = 1
    154 let g:airline_section_y = ''
    155 
    156 " Tagbar
    157 let g:tagbar_width=25
    158 autocmd BufReadPost *.cpp,*.c,*.h,*.cc,*.cxx call tagbar#autoopen()
    159 
    160 "--------------------------------------------------------------------------------
    161 " cscope:建立数据库:cscope -Rbq;  F5 查找c符号; F6 查找字符串;   F7 查找函数定义; F8 查找函数谁调用了,
    162 "--------------------------------------------------------------------------------
    163 if has("cscope")
    164   set csprg=/usr/bin/cscope
    165   set csto=1
    166   set cst
    167   set nocsverb
    168   " add any database in current directory
    169   if filereadable("cscope.out")
    170       cs add cscope.out
    171   endif
    172   set csverb
    173 endif
    174 
    175 
    176 :set cscopequickfix=s-,c-,d-,i-,t-,e-
    177 
    178 nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
    179 nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
    180 nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
    181 nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
    182 nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
    183 nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
    184 nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    185 nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>
    186 
    187 
    188 "nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
    189 "F5 查找c符号; F6 查找字符串;   F7 查找函数定义; F8 查找函数谁调用了,
    190 nmap <silent> <F5> :cs find s <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
    191 nmap <silent> <F6> :cs find t <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
    192 "nmap <silent> <F7> :cs find g <C-R>=expand("<cword>")<CR><CR>
    193 nmap <silent> <F7> :cs find c <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
    194 
    195 
    196  "--------------------------------------------------------------------------------
    197 "  自动加载ctags: ctags -R
    198 if filereadable("tags")
    199       set tags=tags
    200 endif
    201 
    202 "--------------------------------------------------------------------------------
    203 " global:建立数据库
    204 "--------------------------------------------------------------------------------
    205 if filereadable("GTAGS")
    206     set cscopetag
    207     set cscopeprg=gtags-cscope
    208     cs add GTAGS
    209     au BufWritePost *.c,*.cpp,*.h silent! !global -u &
    210 endif
    View Code

    (3)安装插件

    //先找到其在 github.com 的地址,再将配置信息其加入 .vimrc 中的call vundle#begin() 和 call vundle#end() 之间,最后进入 vim 执行
    :PluginInstall
    //要卸载插件,先在 .vimrc 中注释或者删除对应插件配置信息,然后在 vim 中执行
    :PluginClean
    //插件更新频率较高,差不多每隔一个月你应该看看哪些插件有推出新版本,批量更新,只需执行
    :PluginUpdate

    (4)编译自动补全插件 YouCompleteMe

    cd ~/.vim/bundle/YouCompleteMe
    //--clang-completer 表示对C/C++的支持
    ./install.py --clang-completer
    cp third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim
    vim ~/.vimrc
    //添加配置
    let g:ycm_server_python_interpreter='/usr/bin/python'
    let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'

    使用

    (1)生成索引

    //切换到目标代码目录,递归扫描该目录和其子目录的文件并生成索引文件 tags
    sudo ctags -R .
    //-Rb 生成 cscope.out;-q生成 cscope.in.out, cscope.po.out,用于加快索引速度
    sudo cscope -Rbq
    //执行 vim,即可浏览代码
    vim

    (2)vim 键盘图

    来源:http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html

    (3)vim 常用命令

    插入命令

    a      在光标 后 插入
    i                   前
    o      在当前行 后 插入新行
    O                     前
    cw    替换光标至单词尾的字符

    x      删除光标所在字符
    ndd  删除光标开始的n行(会存入剪贴板)
    nyy  拷贝光标开始的n行
    p   粘贴剪贴板
    u   撤销操作
    ctrl+r  redo
    .    重复上一次的命令
    n<cmd>  重复某个命令n次

    光标移动

    nG  到第n行
    gg  到第一行
    G   到最后一行
    hjkl   光标键< ^>
    %   (){}[] 匹配移动
    #   上(匹配光标所在单词)
    *    下
    0    行头,数字零
    $    尾
    ^    行首字符

    w    开头(下一个单词或字符)
    e     结尾
    W   开头(下一个字符串)
    E    结尾

    /str    搜索字符串

    :wq  保存+退出
    :q!  退出不保存
    :qa!  退出不保存所有文件

    :split  水平分屏
    :vsplit  垂直分屏
    ctrl+w+hjkl  选择分屏
    :bn  切换 下 一个文件
    :bp          上
    :e path/file      打开指定文件
    :saveas path/file  另存为
    :help <cmd>   显示cmd info

    :cs
    cscope commands:
    add  : Add a new database             (Usage: add file|dir [pre-path] [flags])
    find : Query for a pattern            (Usage: find a|c|d|e|f|g|i|s|t name)
           a: Find assignments to this symbol
           c: Find functions calling this function
           d: Find functions called by this function
           e: Find this egrep pattern
           f: Find this file
           g: Find this definition
           i: Find files #including this file
           s: Find this C symbol
           t: Find this text string
    help : Show this message              (Usage: help)
    kill : Kill a connection              (Usage: kill #)
    reset: Reinit all connections         (Usage: reset)
    show : Show connections               (Usage: show)

    配置二

    参考:https://github.com/yangyangwithgnu/use_vim_as_ide

    步骤:

    (1)安装插件管理工具vundle

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

    (2)创建~/.vimrc

    .vimrc 是控制 vim 行为的配置文件

      1 " 更新时间:2016-03-30 12:15:21
      2 
      3 " 定义快捷键的前缀,即 <Leader>
      4 let mapleader=";"
      5 
      6 " >>
      7 " 文件类型侦测
      8 
      9 " 开启文件类型侦测
     10 filetype on
     11 " 根据侦测到的不同类型加载对应的插件
     12 filetype plugin on
     13 
     14 " <<
     15 
     16 " >>
     17 " vim 自身(非插件)快捷键
     18 
     19 " 定义快捷键到行首和行尾
     20 nmap LB 0
     21 nmap LE $
     22 
     23 " 设置快捷键将选中文本块复制至系统剪贴板
     24 vnoremap <Leader>y "+y
     25 " 设置快捷键将系统剪贴板内容粘贴至vim
     26 nmap <Leader>p "+p
     27 
     28 " 定义快捷键关闭当前分割窗口
     29 nmap <Leader>q :q<CR>
     30 " 定义快捷键保存当前窗口内容
     31 nmap <Leader>w :w<CR>
     32 " 定义快捷键保存所有窗口内容并退出 vim
     33 nmap <Leader>WQ :wa<CR>:q<CR>
     34 " 不做任何保存,直接退出 vim
     35 nmap <Leader>Q :qa!<CR>
     36 
     37 " 设置快捷键遍历子窗口
     38 " 依次遍历
     39 nnoremap nw <C-W><C-W>
     40 " 跳转至右方的窗口
     41 nnoremap <Leader>lw <C-W>l
     42 " 跳转至方的窗口
     43 nnoremap <Leader>hw <C-W>h
     44 " 跳转至上方的子窗口
     45 nnoremap <Leader>kw <C-W>k
     46 " 跳转至下方的子窗口
     47 nnoremap <Leader>jw <C-W>j
     48 
     49 " 定义快捷键在结对符之间跳转
     50 nmap <Leader>M %
     51 
     52 " <<
     53 
     54 " 让配置变更立即生效
     55 autocmd BufWritePost $MYVIMRC source $MYVIMRC
     56 
     57 " >>
     58 " 其他
     59 
     60 " 开启实时搜索功能
     61 set incsearch
     62 
     63 " 搜索时大小写不敏感
     64 set ignorecase
     65 
     66 " 关闭兼容模式
     67 set nocompatible
     68 
     69 " vim 自身命令行模式智能补全
     70 set wildmenu
     71 
     72 " <<
     73 
     74 " >>>>
     75 " 插件安装
     76 
     77 " vundle 环境设置
     78 filetype off
     79 set rtp+=~/.vim/bundle/Vundle.vim
     80 " vundle 管理的插件列表必须位于 vundle#begin() 和 vundle#end() 之间
     81 call vundle#begin()
     82 
     83 Plugin 'VundleVim/Vundle.vim'
     84 Plugin 'altercation/vim-colors-solarized'
     85 Plugin 'tomasr/molokai'
     86 Plugin 'vim-scripts/phd'
     87 Plugin 'Lokaltog/vim-powerline'
     88 Plugin 'octol/vim-cpp-enhanced-highlight'
     89 Plugin 'nathanaelkane/vim-indent-guides'
     90 Plugin 'derekwyatt/vim-fswitch'
     91 Plugin 'kshenoy/vim-signature'
     92 Plugin 'vim-scripts/BOOKMARKS--Mark-and-Highlight-Full-Lines'
     93 Plugin 'majutsushi/tagbar'
     94 Plugin 'vim-scripts/indexer.tar.gz'
     95 Plugin 'vim-scripts/DfrankUtil'
     96 Plugin 'vim-scripts/vimprj'
     97 Plugin 'dyng/ctrlsf.vim'
     98 Plugin 'terryma/vim-multiple-cursors'
     99 Plugin 'scrooloose/nerdcommenter'
    100 Plugin 'vim-scripts/DrawIt'
    101 Plugin 'SirVer/ultisnips'
    102 Plugin 'derekwyatt/vim-protodef'
    103 Plugin 'scrooloose/nerdtree'
    104 Plugin 'fholgado/minibufexpl.vim'
    105 Plugin 'gcmt/wildfire.vim'
    106 Plugin 'sjl/gundo.vim'
    107 Plugin 'Lokaltog/vim-easymotion'
    108 Plugin 'suan/vim-instant-markdown'
    109 Plugin 'Valloric/YouCompleteMe'
    110 Plugin 'lilydjwg/fcitx.vim'
    111 
    112 " 插件列表结束
    113 call vundle#end()
    114 filetype plugin indent on
    115 " <<<<
    116 
    117 " 配色方案
    118 set background=dark
    119 colorscheme solarized
    120 "colorscheme molokai
    121 "colorscheme phd
    122 
    123 " >>
    124 " 营造专注气氛
    125 
    126 " 禁止光标闪烁
    127 set gcr=a:block-blinkon0
    128 
    129 " 禁止显示滚动条
    130 set guioptions-=l
    131 set guioptions-=L
    132 set guioptions-=r
    133 set guioptions-=R
    134 
    135 " 禁止显示菜单和工具条
    136 set guioptions-=m
    137 set guioptions-=T
    138 
    139 " 将外部命令 wmctrl 控制窗口最大化的命令行参数封装成一个 vim 的函数
    140 fun! ToggleFullscreen()
    141     call system("wmctrl -ir " . v:windowid . " -b toggle,fullscreen")
    142 endf
    143 " 全屏开/关快捷键
    144 map <silent> <F11> :call ToggleFullscreen()<CR>
    145 "" 启动 vim 时自动全屏
    146 "autocmd VimEnter * call ToggleFullscreen()
    147 
    148 " <<
    149 
    150 " >>
    151 " 辅助信息
    152 
    153 " 总是显示状态栏
    154 set laststatus=2
    155 
    156 " 显示光标当前位置
    157 set ruler
    158 
    159 " 开启行号显示
    160 set number
    161 
    162 " 高亮显示当前行/列
    163 set cursorline
    164 set cursorcolumn
    165 
    166 " 高亮显示搜索结果
    167 set hlsearch
    168 
    169 " <<
    170 
    171 " >>
    172 " 其他美化
    173 
    174 " 设置 gvim 显示字体
    175 set guifont=YaHei Consolas Hybrid 10.5
    176 
    177 " 禁止折行
    178 set nowrap
    179 
    180 " 设置状态栏主题风格
    181 let g:Powerline_colorscheme='solarized256'
    182 
    183 " <<
    184 
    185 " >>
    186 " 语法分析
    187 
    188 " 开启语法高亮功能
    189 syntax enable
    190 " 允许用指定语法高亮配色方案替换默认方案
    191 syntax on
    192 
    193 " <<
    194 
    195 " >>
    196 " 缩进
    197 
    198 " 自适应不同语言的智能缩进
    199 filetype indent on
    200 
    201 " 将制表符扩展为空格
    202 set expandtab
    203 " 设置编辑时制表符占用空格数
    204 set tabstop=4
    205 " 设置格式化时制表符占用空格数
    206 set shiftwidth=4
    207 " 让 vim 把连续数量的空格视为一个制表符
    208 set softtabstop=4
    209 
    210 " 缩进可视化插件 Indent Guides
    211 " 随 vim 自启动
    212 let g:indent_guides_enable_on_vim_startup=1
    213 " 从第二层开始可视化显示缩进
    214 let g:indent_guides_start_level=2
    215 " 色块宽度
    216 let g:indent_guides_guide_size=1
    217 " 快捷键 i 开/关缩进可视化
    218 nmap <silent> <Leader>i <Plug>IndentGuidesToggle
    219 
    220 " <<
    221 
    222 " >>
    223 " 代码折叠
    224 
    225 " 基于缩进或语法进行代码折叠
    226 "set foldmethod=indent
    227 set foldmethod=syntax
    228 " 启动 vim 时关闭折叠代码
    229 set nofoldenable
    230 
    231 " <<
    232 
    233 " >>
    234 " 接口与实现快速切换
    235 
    236 " *.cpp 和 *.h 间切换
    237 nmap <silent> <Leader>sw :FSHere<cr>
    238 
    239 " <<
    240 
    241 " >>
    242 " 代码收藏
    243 
    244 " 自定义 vim-signature 快捷键
    245 let g:SignatureMap = {
    246          'Leader'             :  "m",
    247          'PlaceNextMark'      :  "m,",
    248          'ToggleMarkAtLine'   :  "m.",
    249          'PurgeMarksAtLine'   :  "m-",
    250          'DeleteMark'         :  "dm",
    251          'PurgeMarks'         :  "mda",
    252          'PurgeMarkers'       :  "m<BS>",
    253          'GotoNextLineAlpha'  :  "']",
    254          'GotoPrevLineAlpha'  :  "'[",
    255          'GotoNextSpotAlpha'  :  "`]",
    256          'GotoPrevSpotAlpha'  :  "`[",
    257          'GotoNextLineByPos'  :  "]'",
    258          'GotoPrevLineByPos'  :  "['",
    259          'GotoNextSpotByPos'  :  "mn",
    260          'GotoPrevSpotByPos'  :  "mp",
    261          'GotoNextMarker'     :  "[+",
    262          'GotoPrevMarker'     :  "[-",
    263          'GotoNextMarkerAny'  :  "]=",
    264          'GotoPrevMarkerAny'  :  "[=",
    265          'ListLocalMarks'     :  "ms",
    266          'ListLocalMarkers'   :  "m?"
    267          }
    268 
    269 " <<
    270 
    271 " >>
    272 " 标签列表
    273 
    274 " 设置 tagbar 子窗口的位置出现在主编辑区的左边
    275 let tagbar_left=1
    276 " 设置显示/隐藏标签列表子窗口的快捷键。速记:identifier list by tag
    277 nnoremap <Leader>ilt :TagbarToggle<CR>
    278 " 设置标签子窗口的宽度
    279 let tagbar_width=32
    280 " tagbar 子窗口中不显示冗余帮助信息
    281 let g:tagbar_compact=1
    282 " 设置 ctags 对哪些代码标识符生成标签
    283 let g:tagbar_type_cpp = {
    284       'ctagstype' : 'c++',
    285       'kinds'     : [
    286           'c:classes:0:1',
    287           'd:macros:0:1',
    288           'e:enumerators:0:0', 
    289           'f:functions:0:1',
    290           'g:enumeration:0:1',
    291           'l:local:0:1',
    292           'm:members:0:1',
    293           'n:namespaces:0:1',
    294           'p:functions_prototypes:0:1',
    295           's:structs:0:1',
    296           't:typedefs:0:1',
    297           'u:unions:0:1',
    298           'v:global:0:1',
    299           'x:external:0:1'
    300       ],
    301       'sro'        : '::',
    302       'kind2scope' : {
    303           'g' : 'enum',
    304           'n' : 'namespace',
    305           'c' : 'class',
    306           's' : 'struct',
    307           'u' : 'union'
    308       },
    309       'scope2kind' : {
    310           'enum'      : 'g',
    311           'namespace' : 'n',
    312           'class'     : 'c',
    313           'struct'    : 's',
    314           'union'     : 'u'
    315       }
    316  }
    317 
    318 " <<
    319 
    320 " >>
    321 " 代码导航
    322  
    323 " 基于标签的代码导航
    324 
    325 " 设置插件 indexer 调用 ctags 的参数
    326 " 默认 --c++-kinds=+p+l,重新设置为 --c++-kinds=+l+p+x+c+d+e+f+g+m+n+s+t+u+v
    327 " 默认 --fields=+iaS 不满足 YCM 要求,需改为 --fields=+iaSl
    328 let g:indexer_ctagsCommandLineOptions="--c++-kinds=+l+p+x+c+d+e+f+g+m+n+s+t+u+v --fields=+iaSl --extra=+q"
    329 
    330 " 正向遍历同名标签
    331 nmap <Leader>tn :tnext<CR>
    332 " 反向遍历同名标签
    333 nmap <Leader>tp :tprevious<CR>
    334 
    335 " 基于语义的代码导航
    336 
    337 nnoremap <leader>jc :YcmCompleter GoToDeclaration<CR>
    338 " 只能是 #include 或已打开的文件
    339 nnoremap <leader>jd :YcmCompleter GoToDefinition<CR>
    340 
    341 " <<
    342 
    343 " >>
    344 " 查找
    345 
    346 " 使用 ctrlsf.vim 插件在工程内全局查找光标所在关键字,设置快捷键。快捷键速记法:search in project
    347 nnoremap <Leader>sp :CtrlSF<CR>
    348 
    349 " <<
    350 
    351 " >>
    352 " 内容替换
    353 
    354 " 快捷替换
    355 let g:multi_cursor_next_key='<S-n>'
    356 let g:multi_cursor_skip_key='<S-k>'
    357 
    358 " 精准替换
    359 " 替换函数。参数说明:
    360 " confirm:是否替换前逐一确认
    361 " wholeword:是否整词匹配
    362 " replace:被替换字符串
    363 function! Replace(confirm, wholeword, replace)
    364     wa
    365     let flag = ''
    366     if a:confirm
    367         let flag .= 'gec'
    368     else
    369         let flag .= 'ge'
    370     endif
    371     let search = ''
    372     if a:wholeword
    373         let search .= '<' . escape(expand('<cword>'), '/.*$^~[') . '>'
    374     else
    375         let search .= expand('<cword>')
    376     endif
    377     let replace = escape(a:replace, '/&~')
    378     execute 'argdo %s/' . search . '/' . replace . '/' . flag . '| update'
    379 endfunction
    380 " 不确认、非整词
    381 nnoremap <Leader>R :call Replace(0, 0, input('Replace '.expand('<cword>').' with: '))<CR>
    382 " 不确认、整词
    383 nnoremap <Leader>rw :call Replace(0, 1, input('Replace '.expand('<cword>').' with: '))<CR>
    384 " 确认、非整词
    385 nnoremap <Leader>rc :call Replace(1, 0, input('Replace '.expand('<cword>').' with: '))<CR>
    386 " 确认、整词
    387 nnoremap <Leader>rcw :call Replace(1, 1, input('Replace '.expand('<cword>').' with: '))<CR>
    388 nnoremap <Leader>rwc :call Replace(1, 1, input('Replace '.expand('<cword>').' with: '))<CR>
    389 
    390 " <<
    391 
    392 " 模板补全
    393 " UltiSnips 的 tab 键与 YCM 冲突,重新设定
    394 let g:UltiSnipsSnippetDirectories=["mysnippets"]
    395 let g:UltiSnipsExpandTrigger="<leader><tab>"
    396 let g:UltiSnipsJumpForwardTrigger="<leader><tab>"
    397 let g:UltiSnipsJumpBackwardTrigger="<leader><s-tab>"
    398 
    399 " >>
    400 " YCM 补全
    401 
    402 " YCM 补全菜单配色
    403 " 菜单
    404 highlight Pmenu ctermfg=2 ctermbg=3 guifg=#005f87 guibg=#EEE8D5
    405 " 选中项
    406 highlight PmenuSel ctermfg=2 ctermbg=3 guifg=#AFD700 guibg=#106900
    407 
    408 " 补全功能在注释中同样有效
    409 let g:ycm_complete_in_comments=1
    410 
    411 " 允许 vim 加载 .ycm_extra_conf.py 文件,不再提示
    412 let g:ycm_confirm_extra_conf=0
    413 
    414 " 开启 YCM 标签补全引擎
    415 let g:ycm_collect_identifiers_from_tags_files=0
    416 "" 引入 C++ 标准库 tags
    417 "set tags+=/data/misc/software/app/vim/stdcpp.tags
    418 "set tags+=/data/misc/software/app/vim/sys.tags
    419 
    420 " YCM 集成 OmniCppComplete 补全引擎,设置其快捷键
    421 inoremap <leader>; <C-x><C-o>
    422 
    423 " 补全内容不以分割子窗口形式出现,只显示补全列表
    424 set completeopt-=preview
    425 
    426 " 从第一个键入字符就开始罗列匹配项
    427 let g:ycm_min_num_of_chars_for_completion=1
    428 
    429 " 禁止缓存匹配项,每次都重新生成匹配项
    430 let g:ycm_cache_omnifunc=0
    431 
    432 " 语法关键字补全
    433 let g:ycm_seed_identifiers_with_syntax=1
    434 
    435 " <<
    436  
    437 " >>
    438 " 由接口快速生成实现框架
    439 
    440 " 成员函数的实现顺序与声明顺序一致
    441 let g:disable_protodef_sorting=1
    442 
    443 " <<
    444 
    445 " >>
    446 " 库信息参考
    447  
    448 " 启用:Man命令查看各类man信息
    449 source $VIMRUNTIME/ftplugin/man.vim
    450 
    451 " 定义:Man命令查看各类man信息的快捷键
    452 nmap <Leader>man :Man 3 <cword><CR>
    453 
    454 " <<
    455 
    456 " >>
    457 " 工程文件浏览
    458 
    459 " 使用 NERDTree 插件查看工程文件。设置快捷键,速记:file list
    460 nmap <Leader>fl :NERDTreeToggle<CR>
    461 " 设置 NERDTree 子窗口宽度
    462 let NERDTreeWinSize=22
    463 " 设置 NERDTree 子窗口位置
    464 let NERDTreeWinPos="right"
    465 " 显示隐藏文件
    466 let NERDTreeShowHidden=1
    467 " NERDTree 子窗口中不显示冗余帮助信息
    468 let NERDTreeMinimalUI=1
    469 " 删除文件时自动删除文件对应 buffer
    470 let NERDTreeAutoDeleteBuffer=1
    471 
    472 " <<
    473 
    474 " >>
    475 " 多文档编辑
    476  
    477 " 显示/隐藏 MiniBufExplorer 窗口
    478 map <Leader>bl :MBEToggle<cr>
    479 
    480 " buffer 切换快捷键
    481 map <C-Tab> :MBEbn<cr>
    482 map <C-S-Tab> :MBEbp<cr>
    483 
    484 " <<
    485 
    486 
    487 " >>
    488 " 环境恢复
    489 
    490 " 设置环境保存项
    491 set sessionoptions="blank,globals,localoptions,tabpages,sesdir,folds,help,options,resize,winpos,winsize"
    492 
    493 " 保存 undo 历史。必须先行创建 .undo_history/
    494 set undodir=~/.undo_history/
    495 set undofile
    496 
    497 " 保存快捷键
    498 "map <leader>ss :mksession! my.vim<cr> :wviminfo! my.viminfo<cr>
    499 map <leader>ss :mksession! my.vim<cr>
    500 
    501 " 恢复快捷键
    502 "map <leader>rs :source my.vim<cr> :rviminfo my.viminfo<cr>
    503 map <leader>rs :source my.vim<cr>
    504 
    505 " <<
    506  
    507 " 设置快捷键实现一键编译及运行
    508 nmap <Leader>m :wa<CR> :cd build/<CR> :!rm -rf main<CR> :!cmake CMakeLists.txt<CR>:make<CR><CR> :cw<CR> :cd ..<CR>
    509 nmap <Leader>g :wa<CR>:cd build/<CR>:!rm -rf main<CR>:!cmake CMakeLists.txt<CR>:make<CR><CR>:cw<CR>:cd ..<CR>:!build/main<CR>
    510 
    511 " >>
    512 " 快速选中结对符内的文本
    513  
    514 " 快捷键
    515 map <SPACE> <Plug>(wildfire-fuel)
    516 vmap <S-SPACE> <Plug>(wildfire-water)
    517 
    518 " 适用于哪些结对符
    519 let g:wildfire_objects = ["i'", 'i"', "i)", "i]", "i}", "i>", "ip"]
    520 
    521 " <<
    522 
    523 " 调用 gundo 树
    524 nnoremap <Leader>ud :GundoToggle<CR>
    View Code

     (3)安装插件

    //先找到其在 github.com 的地址,再将配置信息其加入 .vimrc 中的call vundle#begin() 和 call vundle#end() 之间,最后进入 vim 执行
    :PluginInstall
    //要卸载插件,先在 .vimrc 中注释或者删除对应插件配置信息,然后在 vim 中执行
    :PluginClean
    //插件更新频率较高,差不多每隔一个月你应该看看哪些插件有推出新版本,批量更新,只需执行
    :PluginUpdate

    安装完成后,执行vim,可能会报错:

    Indexer error: Exuberant Ctags not found in PATH. You need to install Ctags to make Indexer work.
    ==>
    sudo apt-get install ctags
    
    socket file of fcitx not found, fcitx.vim not loaded.
    ==>
    需要安装 fcitx,详见步骤(4
    The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need to compile YCM before using it. Follow the instructions in the documentation.
    ==>
    cd .vim/bundle/YouCompleteMe/
    ./install.py 
        ERROR: Unable to find executable 'cmake'. CMake is required to build ycmd
        ==>
        sudo apt-get install cmake
    
     ./install.py 
        Searching Python 2.7 libraries...
        ERROR: Python headers are missing in /usr/include/python2.7.
        ==>
        dpkg --get-selections | grep python-dev //查看是否安装python 
        ls /usr/include/python2.7/ //查看是否有Python.h
        sudo apt-get install python-dev
    
     ./install.py 

    (4)安装 fcitx 输入法

    参考:https://www.cnblogs.com/jecyhw/p/4166486.html

    socket file of fcitx not found, fcitx.vim not loaded.
    ==>
    //ubuntu 默认是安装了ibus,可以先删除
    sudo apt-get remove ibus
    //删除已安装的fcitx
    sudo apt-get remove fcitx*
    //删除依赖库
    sudo apt-get autoremove
    //检测是否删除fcitx
    dpkg --get-selections | grep fcitx
    //删除fcitx相关配置文件
    dpkg --purge `dpkg --get-selections | grep deinstall | cut -f1`;
    
    //添加源
    sudo add-apt-repository ppa:fcitx-team/nightly
    //更新源
    sudo apt-get update
    //安装fcitx输入法
    sudo apt-get install fcitx fcitx-config-gtk fcitx-sunpinyin fcitx-googlepinyin fcitx-module-cloudpinyin im-config
    //设置fcitx为默认输入法
    sudo im-config -s fcitx -z default
    //安装搜狗输入法,下载链接 http://pinyin.sogou.com/linux/
    sudo dpkg -i /home/cindy/work/sogoupinyin_2.2.0.0108_amd64.deb 
        dpkg: error processing package sogoupinyin (--install):  
          dependency problems - leaving unconfigured
        ==>
      sudo apt-get -f install //修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的   sudo dpkg -i /home/cindy/work/sogoupinyin_2.2.0.0108_amd64.deb

    配置 fcitx

  • 相关阅读:
    规划支持系统的现状与发展方向
    环境影响评价的概念和指标体系
    DTD to XSD的在线免费转换工具
    如何在64位IIS中启用32位支持
    Entity Framework 1.0中的日期比较
    安装Office 2010 beta后Visual Studio 2008的Web设计器失去响应的问题
    为何由WSDL.exe生成的Web服务代理类无法正确的序列化枚举类型?因为……
    如何为一个XML文件进行DTD验证
    释放VB.NET下Linq to XML的智能提示的威力
    Entity Framework概述 For 终结者
  • 原文地址:https://www.cnblogs.com/sunnycindy/p/9903794.html
Copyright © 2011-2022 走看看