首页 > 技术文章 > 配置vim

megachen 2018-11-29 17:29 原文

配置vim

我的VIM配置文件(在这之前先安装并配置Vundle)

  • .vimrc

" ************************** Basic Settings *************************
set nocompatible              " required, so don't remove it.
filetype off                  " required, so don't remove it.
syntax on
set hlsearch
set ts=4                      " set tab space
set expandtab
set sw=4
set ic                        " ignore case
set ai
set ci
set nu                        " show line number
set ruler
set wildmenu
set showcmd
hi Pmenu ctermbg=lightblue

set nofoldenable
set encoding=utf8
" set foldmethod=indent
set clipboard=unnamed       " let vim share the clipboard with system -> really useful.

set completeopt-=preview
set completeopt=longest,menu
set relativenumber

au BufWinLeave * silent mkview  "
au BufRead * silent loadview    "






" ******************* Customized Keyboard Mapping ***********************
nnoremap <space> za             " open/close code folding.
let mapleader = "@"





" ******************* Keyboard Mapping For CompleteParameter.vim Plugin ***************
" ************* Github: https://github.com/tenfyzhong/CompleteParameter.vim **********
inoremap <silent><expr> ( complete_parameter#pre_complete("()")
smap <c-j> <Plug>(complete_parameter#goto_next_parameter)
imap <c-j> <Plug>(complete_parameter#goto_next_parameter)
smap <c-k> <Plug>(complete_parameter#goto_previous_parameter)
imap <c-k> <Plug>(complete_parameter#goto_previous_parameter)


" *** Warning area(You'd better don't modify anything here) **
" It's necessary to set ycm_global_ycm_extra_conf variable here so that the YCM can work.
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
let g:ycm_key_invoke_completion = '<c-k>' " code hint

" auto complete when you input 2 characters
let g:ycm_semantic_triggers =  {
            \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
            \ 'cs,lua,javascript': ['re!\w{2}'],
            \ }

" close code syntax checking
" let g:ycm_show_diagnostics_ui = 0

let g:ycm_min_num_of_chars_for_completion=1

let g:indentLine_char = "┆"
let g:indentLine_enabled = 1
let g:autopep8_disable_show_diff=1

" ================ Setting for vim status line ===============
set rtp+=~/.vim/bundle/powerline/powerline/bindings/vim
set guifont=Sauce\ Code\ Powerline:h14.5
set laststatus=2
set encoding=utf-8
set t_Co=256
set number
set fillchars+=stl:\ ,stlnc:\
set term=xterm-256color
set termencoding=utf-8
set background=light


" ============================================================

set rtp+=~/.vim/bundle/Vundle.vim
set rtp+=~/.vim/bundle/CompleteParameter.vim
call vundle#begin()

" different from other Plugins, this `Plugin 'gmarik/Vundle.vim'` statement should
" be written here.
Plugin 'gmarik/Vundle.vim'

call vundle#end()            " required, so don't remove it.
filetype plugin indent on    " required, so don't remove it.


" ********************** Plugin Area ************************
" Install Plugin
" autocmd vimenter * NERDTree

Plugin 'tmhedberg/SimpylFold'
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'         " use ctrl + p to search files
Plugin 'scrooloose/nerdcommenter'   " commenter: \cc \cu -> use `\cc` to comment code, use `\cu` to uncomment code
Plugin 'Yggdroot/indentLine'
Plugin 'powerline/powerline'
Plugin 'fatih/vim-go'
Plugin 'liuchengxu/space-vim-dark'
Plugin 'Chiel92/vim-autoformat'
Plugin 'kien/rainbow_parentheses.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'liuchengxu/eleline.vim'

" ********************* Settings for Plugin liuchengxu/space-vim-dark(Please Don't modify these) ********************
colorscheme space-vim-dark
hi Normal     ctermbg=NONE guibg=NONE
hi LineNr     ctermbg=NONE guibg=NONE
hi SignColumn ctermbg=NONE guibg=NONE
color space-vim-dark
set termguicolors
hi LineNr ctermbg=NONE guibg=NONE


" ************************ Settings for Plugin syntastic*********************
execute pathogen#infect()
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

" ********** Settings for Plugin kien/rainbow_parentheses.vim**
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


"********* Settings for Plugin autoformat ************
au BufWrite * :Autoformat


"********** Settings for Plugin eleline.vim **********
set laststatus=2
let g:airline_powerline_fonts = 1



  • 在终端打开vim输入:PluginInstall安装插件
  • 在安装YCM插件的很慢需要等很久, 耐心等待吧
  • 安装完毕YCM之后需要进入到目录中编译YCM, 在编译之前需要安装一些依赖程序, 如CMake, 同时建议在编译的时候不要使用--all, 一般情况下会报错产生一些问题, 只用添加--clang的语句分析即可
  • 对于syntastic插件, 配置文件中相关的设置已经写好的, 但是安装需要参考https://github.com/vim-syntastic/syntastic, 注意不需要动配置文件, 已经添加进去了
  • 更加详细的参考VIM搭建IDE
  • 如果要支持C++11, 则在末尾追加let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++'

推荐阅读