Vim配置笔记

1、安装vim

sudo dnf install vim

2、插件管理

选择vim-plug,vim-plug 是韩国人junegunn (Junegunn Choi) 写的, 目前最快插件管理器,无论是更新,安装,全都是并发的 ( https://github.com/junegunn/vim-plug ) 。
在用户目录下下载Vim-plug并把它放在autoload目录里:

curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
执行完以上命令,再在.vim目录下新建一个plugged目录,用来放置插件,最终.vim目录下有autoload和plugged两个目录。

3、.vimrc配置

call plug#begin('~/.vim/plugged')

" Shorthand notation; fetches https://github.com/Valloric/YouCompleteMe.git
Plug 'Valloric/YouCompleteMe' " 自动补全
Plug 'scrooloose/nerdtree' " 树形目录
Plug 'Xuyuanp/nerdtree-git-plugin' " 树形目录git支持
Plug 'vim-airline/vim-airline' " 状态栏增强
Plug 'vim-airline/vim-airline-themes' " 状态栏主题
Plug 'majutsushi/tagbar' " 右边窗口
Plug 'morhetz/gruvbox' " 配色主题
Plug 'kien/ctrlp.vim' " 搜索插件
Plug 'Yggdroot/indentLine' " 缩进线
Plug 'vim-scripts/indentpython.vim' " python自动缩进
Plug 'w0rp/ale' " 代码检测
Plug 'nvie/vim-flake8' " 添加flake8代码风格检查
Plug 'tell-k/vim-autopep8' " 自动格式化工具
Plug 'Chiel92/vim-autoformat' " 自动的一键格式化代码
Plug 'tpope/vim-fugitive' " git集成插件
Plug 'mhinz/vim-startify' " 展示最近打开文件
Plug 'kien/rainbow_parentheses.vim' " 不同颜色区分括号匹配

" Initialize plugin system
call plug#end()

" ==========================================================
" < 基础的配置 >
" ==========================================================

set nocompatible " 关闭与vi的兼容模式
set number " 显示行号
set nowrap " 不自动折行
set showmatch " 显示匹配的括号
set scrolloff=3 " 距离顶部和底部3行
set encoding=utf-8 " 编码
set fileencodings=utf-8,ucs-bom,GB2312,big5 " 编码
set mouse=a " 启用鼠标
set hlsearch " 搜索高亮
syntax on " 语法高亮

" 按F5自动执行代码
map :call CompileRunGcc()
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!gcc % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'python'
exec "!clear"
exec "!time python3 %"
endif
endfunc

" 代码折叠
set foldmethod=indent
set foldlevel=99
" 使用zc组合键创建折叠,使用za打开或关闭折叠
" 用空格键来替代za
nnoremap za

" 分割窗口
set splitbelow
set splitright
" 设置窗口之间切换快捷键
nnoremap " Ctrl-j 切换到下面
nnoremap " Ctrl-k 切换到上面
nnoremap " Ctrl-l 切换到右面
nnoremap " Ctrl-h 切换到左面

" 设置python代码按照PEP8 标准进行缩进
au BufNewFile,BufRead *.py
\ set tabstop=4 " tab宽度
\ set softtabstop=4
\ set shiftwidth=4
\ set textwidth=79 " 行最大宽度
\ set expandtab " tab替换为空格键
\ set autoindent " 自动缩进
\ set fileformat=unix " 保存文件格式

" ==========================================================
" < 插件的配置 >
" ==========================================================

" NERD tree Configure
let NERDChristmasTree=0
let NERDTreeWinSize=30
let NERDTreeChDirMode=2
let NERDTreeIgnore=['~$', '.pyc$', '.swp$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos="left"
" Automatically open a NERDTree if no files where specified
autocmd vimenter * if !argc() | NERDTree | endif
" Close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" 快捷键配置
nmap :NERDTreeToggle

" Tagbar Configure
let g:tagbar_width=30
let g:tagbar_autofocus=0
let g:tagbar_ctags_bin='/usr/bin/ctags'
autocmd BufReadPost .cpp,.c,.h,.hpp,.cc,.cxx call tagbar#autoopen()
nmap :TagbarToggle
"需要在代码的目录下执行:ctags -R *

" Airline Configure
" 永远显示状态栏
set laststatus=2
" 安装字体后必须设置
let g:airline_powerline_fonts = 1
" 选择airline主题
let g:airline_theme='bubblegum'
" 打开tabline功能,方便查看Buffer和切换,省去了minibufexpl插件
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
" 设置切换Buffer快捷键"
nnoremap :bn
nnoremap :bp
" 关闭状态显示空白符号计数
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#whitespace#symbol = '!'
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
"unicode symbols
let g:airline_left_sep = '?'
let g:airline_left_alt_sep = '?'
let g:airline_right_sep = '?'
let g:airline_right_alt_sep = '?'
let g:airline_symbols.linenr = '?'
let g:airline_symbols.branch = '?'

" Rainbow_parentheses Configure
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces

" Color Configure
syntax enable
" Set syntax highlighting for specific file types
autocmd BufRead,BufNewFile *.md set filetype=markdown
" Color scheme
set background=dark
colorscheme gruvbox
" Highlight current line
au WinLeave * set nocursorline nocursorcolumn
au WinEnter * set cursorline cursorcolumn
set cursorline cursorcolumn

" IndentLine Configure
let g:indentLine_char='┆'
let g:indentLine_enabled = 1

" Ale Configure
let g:ale_fix_on_save = 1
let g:ale_completion_enabled = 1
let g:ale_sign_column_always = 1
let g:airline#extensions#ale#enabled = 1

" Autopep8 Configure
let g:autopep8_disable_show_diff=1
autocmd FileType python noremap :call Autopep8()

" Autoformat Configure
nnoremap :Autoformat
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0

" YouCompleteMe Configure
" 设置全局配置文件的路径
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
" 打开vim时不再询问是否加载ycm_extra_conf.py配置"
let g:ycm_confirm_extra_conf=0
" python解释器路径"
let g:ycm_python_binary_path = '/usr/bin/python2.7'
" 不需要用户主动触发就自动弹出
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}'],
\ }
" 让Vim的补全菜单行为与一般IDE一致
set completeopt=longest,menu
" 离开插入模式后自动关闭预览窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" 回车即选中当前项
inoremap pumvisible() ? "<C-y>" : "<CR>"
" youcompleteme 默认tab s-tab 和 ultisnips 冲突
let g:ycm_key_list_select_completion = ['']
let g:ycm_key_list_previous_completion = ['']
" 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 从第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
" 注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
let g:clang_user_options='|| exit 0'
" 跳转到定义处
nnoremap jd :YcmCompleter GoToDefinition
" 跳转到申明处
nnoremap gl :YcmCompleter GoToDeclaration
" 跳转到定义处或者申明处
nnoremap gg :YcmCompleter GoToDefinitionElseDeclaration

4:、安装插件

在vim normal模式下输入:PlugInstall,等待安装完成

5、YouCompleteMe配置

安装clang:

sudo dnf install clang
进入目录:
cd ~/.vim/plugged/YouCompleteMe
编译:
./install.sh --clang-completer --system-libclang

--clang-completer表示支持c系列补全。

配置.ycm_extra_conf.py:
先复制到~目录

cp ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/
再修改
vim ~/.ycm_extra_conf.py

用命令查看库路径:

echo | clang -v -E -x c++ -
结果可能如下:
clang version 3.6.2 (tags/RELEASE_362/final)
Target: i386-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.7
Found candidate GCC installation: /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1
Selected GCC installation: /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1
Candidate multilib: .;@m32
Selected multilib: .;@m32
太长了,这里省略一部分中间内容;.........表示生咯的内容
这里就是需要包含的路径下面这些都是需要包含的路径
/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1
/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1/i686-pc-linux-gnu
/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward
/usr/local/include
/usr/local/bin/../lib/clang/3.6.2/include
/usr/include

整理上述内容,并添加到flag中

将以上内容复制出来,修改成如下:
'-isystem',
'/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1',
'-isystem',
'/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1/i686-pc-linux-gnu',
'-isystem',
'/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward',
'-isystem',
'/usr/local/include',
'-isystem',
'/usr/local/bin/../lib/clang/5.0.1/include',
'-isystem',
'/usr/include',

posted @ 2018-01-23 21:56  mebob  阅读(234)  评论(0编辑  收藏  举报