vimrc易读精简版(100ms启动)

vimrc

@bolun365
""""""""""""""""""""""""""
"     非特定文件数据加载
""""""""""""""""""""""""""
set viminfo+=!                     "Save and restore global variables
set tags=./tags " for ctags (ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .)
" for cscope (cscope -Rbq)
if has("cscope")
  set csprg=$vim/cscope/cscope | set csto=1 | set cst | set nocsverb
  if filereadable("cscope.out")    "读取cscope数据库
    cs add cscope.out 
  endif 
  set csverb
endif

""""""""""""""""""""""""""
"     特定文件数据加载
""""""""""""""""""""""""""
set backup "备份文件
set noswapfile  "不产生swap文件
set autoread " Set to auto read when a file is changed from the outside
au! BufWritePost .vimrc source ~/.vimrc " vimrc 更新后自动加载
au VimLeave * mksession! .vimsession "loading last conversation
if argc() == 0
    if filereadable(".vimsession") | source .vimsession | else | source $HOME/.vimsession | endif
endif
"让vim记忆上次编辑的位置
autocmd BufReadPost * 
    \if !exists("b:status_loaded") |
    \   if line("'\"")>0 && line("'\"")<=line("$") |
    \       exe "normal! g`\"" |
    \       let b:status_loaded = 1 |
    \   endif |
    \endif

""""""""""""""""""""""""""
"     文件类型文件编码
""""""""""""""""""""""""""
filetype plugin indent on | syntax on
au! BufRead,BufNewFile *.js set filetype=javascript
au! BufRead,BufNewFile *.tpl set filetype=html
au! BufRead,BufNewFile *.proto set filetype=proto
au! BufRead,BufNewFile *.go set filetype=go
au! BufRead,BufNewFile *.py set filetype=python
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set fileformat=unix

""""""""""""""""""""""""""
"     显示
""""""""""""""""""""""""""
set number | set ruler | set fillchars=vert:\ ,stl:\ ,stlnc:\ "状态显示
set foldenable | set foldmethod=syntax | set foldlevelstart=99 "开启语法折叠,但默认不折叠
set showmatch "match } for {
set wrap | set linebreak "折行
set hlsearch "high light the string in searching
set t_Co=256 "釆用256色配色方案
highlight Pmenu ctermbg=8 guibg=#606060
highlight PmenuSel ctermbg=1 guifg=#dddd00 guibg=#1f82cd
highlight PmenuSbar ctermbg=0 guibg=#d6d6d6

""""""""""""""""""""""""""
"     编辑
""""""""""""""""""""""""""
set autoindent | set smartindent | set cindent "对齐
set expandtab | set numberwidth=4 | set tabstop=4 | set linespace=4 | set softtabstop=4 | set shiftwidth=4 

""""""""""""""""""""""""""
"     Control
""""""""""""""""""""""""""
set scrolloff=3  "leave N lines before or after cursors
set incsearch    "输入搜素词时实时跳转
set wildmenu     "命令行补全(tab)时,在状态栏上用列表显示出来
set wildmode=longest,list,full  "在命令行中,先匹配最长公共部分,再列出不能匹配的list,再按list顺序一一选择
set completeopt=longest,menuone,preview
nnoremap <CR> G
vnoremap <silent> y y`] "光标移动到复制的部分后
vnoremap <silent> p p`] | nnoremap <silent> p p`] "光标移动到粘贴的部分后
" Make a simple "search" text object.
vnoremap <silent> s //e<C-r>=&selection=='exclusive'?'+1':''<CR><CR>
    \:<C-u>call histdel('search',-1)<Bar>let @/=histget('search',-1)<CR>gv
omap s :normal vs<CR>

""""""""""""""""""""""""""
"     自定义快捷键
""""""""""""""""""""""""""
let mapleader = "\<Space>"
"for edit
nnoremap <Leader>w :w<CR>
"for search
nmap <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr> "grep当前单词
"quick search
vnoremap // y/<C-R>"<CR>
"for windows
nmap <silent> <leader>b :resize+10<cr>
nmap <silent> <leader>vb :vertical resize+10<cr>
nmap <C-J> <C-W>j<C-W>_ " 在分割窗口中快速切换
nmap <C-K> <C-W>k<C-W>_ " 在分割窗口中快速切换
nmap <C-H> <C-W>h<C-W>_ " 在分割窗口中快速切换
nmap <C-L> <C-W>l<C-W>_ " 在分割窗口中快速切换
nmap <silent> <leader>H <C-W>H
nmap <silent> <leader>J <C-W>J
nmap <silent> <leader>K <C-W>K
nmap <silent> <leader>L <C-W>L 
"for git
command! -bar G GitGutterEnable | e | Gblame
"tabs   gt Gt to switch tab "cmap tn tabnew "cmap to tabonly "nmap <C-c> :tabclose<CR>

""""""""""""""""""""""""""
"     插件配置
""""""""""""""""""""""""""
" YouCompleteMe {
    if isdirectory(expand("~/.vim/plugged/YouCompleteMe"))
        let g:acp_enableAtStartup = 0
        let g:ycm_global_ycm_extra_conf = '~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

        " enable completion from tags
        let g:ycm_collect_identifiers_from_tags_files = 1

        " snippets {
            " remap Ultisnips for compatibility for YCM
            let g:UltiSnipsExpandTrigger = '<C-j>'
            let g:UltiSnipsJumpForwardTrigger = '<C-j>'
            let g:UltiSnipsJumpBackwardTrigger = '<C-k>'
        " }

        " Enable omni completion.
        autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
        autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
        autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
        autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
        autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
        autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
        autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc

        " Disable the neosnippet preview candidate window
        " When enabled, there can be too much visual noise
        " especially when splits are used.
        set completeopt-=preview
    endif
" }

" NerdTree {
    if isdirectory(expand("~/.vim/plugged/The-NERD-tree"))
        nmap <C-e> <plug>NERDTreeTabsToggle<CR>
        nmap <leader>e :NERDTreeToggle<CR>
        nmap <leader>nt :NERDTreeFind<CR>

        let NERDTreeShowBookmarks=1
        let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$']
        let NERDTreeChDirMode=0
        let NERDTreeQuitOnOpen=1
        let NERDTreeMouseMode=2
        let NERDTreeShowHidden=1
        let NERDTreeKeepTreeInNewTab=1
        let g:nerdtree_tabs_open_on_gui_startup=0
    endif
" }

" ctrlp {
    if isdirectory(expand("~/.vim/plugged/ctrlp.vim/"))
        let g:ctrlp_working_path_mode = 'ra'
        nnoremap <c-p> :CtrlP<CR>
        nnoremap <silent> <D-r> :CtrlPMRU<CR>
        let g:ctrlp_custom_ignore = {
            \ 'dir':  '\.git$\|\.hg$\|\.svn$',
            \ 'file': '\.exe$\|\.so$\|\.dll$\|\.pyc$' }

        if executable('ag')
            let s:ctrlp_fallback = 'ag %s --nocolor -l -g ""'
        elseif executable('ack-grep')
            let s:ctrlp_fallback = 'ack-grep %s --nocolor -f'
        elseif executable('ack')
            let s:ctrlp_fallback = 'ack %s --nocolor -f'
        else
            let s:ctrlp_fallback = 'find %s -type f'
        endif
        if exists("g:ctrlp_user_command")
            unlet g:ctrlp_user_command
        endif
        let g:ctrlp_user_command = {
            \ 'types': {
                \ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
                \ 2: ['.hg', 'hg --cwd %s locate -I .'],
            \ },
            \ 'fallback': s:ctrlp_fallback
        \ }

        if isdirectory(expand("~/.vim/plugged/ctrlp-funky/"))
            " CtrlP extensions
            let g:ctrlp_extensions = ['funky']

            "funky
            nnoremap <Leader>fu :CtrlPFunky<Cr>
        endif
    endif
"}

" Tabularize {
    if isdirectory(expand("~/.vim/plugged/tabular"))
        nmap <Leader>a& :Tabularize /&<CR>
        vmap <Leader>a& :Tabularize /&<CR>
        nmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
        vmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
        nmap <Leader>a=> :Tabularize /=><CR>
        vmap <Leader>a=> :Tabularize /=><CR>
        nmap <Leader>a: :Tabularize /:<CR>
        vmap <Leader>a: :Tabularize /:<CR>
        nmap <Leader>a:: :Tabularize /:\zs<CR>
        vmap <Leader>a:: :Tabularize /:\zs<CR>
        nmap <Leader>a, :Tabularize /,<CR>
        vmap <Leader>a, :Tabularize /,<CR>
        nmap <Leader>a,, :Tabularize /,\zs<CR>
        vmap <Leader>a,, :Tabularize /,\zs<CR>
        nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
        vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
    endif
" }

" UndoTree {
    if isdirectory(expand("~/.vim/plugged/undotree/"))
        nnoremap <Leader>u :UndotreeToggle<CR>
        let g:undotree_SetFocusWhenToggle=1
    endif
" }

" WinManager {
    if isdirectory(expand("~/.vim/plugged/winmanager"))
        let g:winManagerWindowLayout = "BufExplorer|TagList"
        nmap <silent> <leader>swm :WMToggle<cr> 
    endif
" }

" vim-expand-region {
    if isdirectory(expand("~/.vim/plugged/vim-expand-region"))
        vmap v <Plug>(expand_region_expand)
        vmap <C-v> <Plug>(expand_region_shrink)
    endif
" }

" GoLang {
    let g:go_highlight_functions = 1
    let g:go_highlight_methods   = 1
    let g:go_highlight_structs = 1
    let g:go_highlight_operators = 1
    let g:go_highlight_build_constraints = 1
    let g:go_fmt_command = "goimports"
    let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck']
    let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
    au FileType go nmap <Leader>s <Plug>(go-implements)
    au FileType go nmap <Leader>i <Plug>(go-info)
    au FileType go nmap <Leader>e <Plug>(go-rename)
    au FileType go nmap <leader>r <Plug>(go-run)
    au FileType go nmap <leader>b <Plug>(go-build)
    au FileType go nmap <leader>t <Plug>(go-test)
    au FileType go nmap <Leader>gd <Plug>(go-doc)
    au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
    au FileType go nmap <leader>co <Plug>(go-coverage)
" }

""""""""""""""""""""""""""
"     插件安装
""""""""""""""""""""""""""
"" plug下载
""      mkdir -p ~/.vim/autoload/
""      curl https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim >> ~/.vim/autoload/plug.vim  
"" libstdc 更新
""      wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.gz
""      tar -xvzf gcc-4.8.1.tar.gz; cd gcc-4.8.1; ./contrib/download_prerequisites;
""      cd ..; mkdir build_gcc_4.8.1; cd build_gcc_4.8.1;
""      ../gcc-4.8.1/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
""      make -j23; sudo make install
""      cd x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/
""      sudo cp libstdc++.so.6.0.18 /usr/lib64/
""      cd /usr/lib64/
""      sudo ln -sf libstdc++.so.6.0.18 libstdc++.so.6 
"" vim 开启 python 支持
""      yum install python-devel
""      ./configure  --enable-pythoninterp --with-python-config-dir=/usr/lib64/python2.6/config   --enable-luainterp  --enable-fail-if-missing  --with-lua-prefix=/usr
"" YouCompleteMe编译
""      (需要libc支持)./.vim/plugged/YouCompleteMe/install.sh --clang-completer --gocode-completer
"" 在vim中:GoInstallBinaries
"" syntastic插件:对于python需要pip install pylint
call plug#begin('~/.vim/plugged')
Plug 'gmarik/vundle'
Plug 'vim-scripts/L9'
Plug 'vim-scripts/mark'
Plug 'vim-scripts/ag.vim'
Plug 'vim-scripts/taglist.vim'
Plug 'jlanzarotta/bufexplorer'
Plug 'vim-scripts/winmanager', { 'on':  'WMToggle' }
Plug 'vim-scripts/The-NERD-tree', { 'on':  'NERDTreeToggle' }
Plug 'vim-scripts/FuzzyFinder', { 'on':  'CtrlP' }
Plug 'ctrlpvim/ctrlp.vim', { 'on':  'CtrlP' }
Plug 'terryma/vim-expand-region', { 'on':  ['<Plug>(expand_region_expand)', '<Plug>(expand_region_shrink)'] }
Plug 'Lokaltog/vim-easymotion'
Plug 'vim-scripts/a.vim', { 'on':  'A' }
Plug 'vim-scripts/The-NERD-Commenter'
Plug 'godlygeek/tabular', { 'on':  'Tabularize' }
Plug 'scrooloose/syntastic', { 'on':  'TriggerSyntastic', 'do': 'echo command! -bar TriggerSyntastic     let a=1 > ~/.vim/plugged/syntastic/plugin/load.plugin.trigger.vim' }
Plug 'mbbill/undotree', { 'on':  'UndotreeToggle' }
Plug 'fatih/vim-go', { 'for': 'go' }
Plug 'Blackrush/vim-gocode', { 'for': 'go' }
Plug 'SirVer/ultisnips', { 'on':  'TriggerUltisnips', 'do': 'echo command! -bar TriggerUltisnips     let a=1 > ~/.vim/plugged/ultisnips/plugin/load.plugin.trigger.vim' } 
Plug 'honza/vim-snippets', { 'on':  'TriggerVimSnippets', 'do': 'echo command! -bar TriggerVimSnippets   let a=1 > ~/.vim/plugged/vim-snippets/plugin/load.plugin.trigger.vim' } 
Plug 'airblade/vim-gitgutter', { 'on':  'GitGutterEnable' }
Plug 'tpope/vim-fugitive', { 'on':  'GitGutterEnable' }
Plug 'Valloric/YouCompleteMe', { 'on':  'TriggerYouCompleteMe', 'do': './install.py;echo command! -bar TriggerYouCompleteMe let a=1 > ~/.vim/plugged/YouCompleteMe/plugin/load.plugin.trigger.vim' } 
call plug#end()

""""""""""""""""""""""""""
"     插件加载优化(提高打开vim时的速度)
""""""""""""""""""""""""""
autocmd BufWritePre * TriggerSyntastic
autocmd CursorHold * TriggerUltisnips | TriggerVimSnippets | TriggerYouCompleteMe
autocmd InsertEnter * TriggerUltisnips | TriggerVimSnippets | TriggerYouCompleteMe

""""""""""""""""""""""""""
"     帮助文档
""""""""""""""""""""""""""
" <ctrl>+h/j/k/l          窗口管理(自定义快捷键)
" <space>+H/J/K/L         窗口管理(自定义快捷键)
" <space>+vb/b            窗口管理(自定义快捷键)
" <space>lv               grep当前单词(自定义快捷键)
" <space>w                保存文件(自定义快捷键)
" 12<CR>                  跳转到第12行(自定义快捷键)
" <space>e                NerdTree打开关闭
" <space>c<space>         注释/取消注释
" <c-p>                   快速查找文件
" <space>a=               对=进行对齐操作
" <space>a:               对:进行对齐操作
" <space>u                undotree
" <space><space>e/b/j/k   easymotion 
" (vmode)//               quick search
" <space>swm              buffer explorer;tag list 
" <space>m                colored mark
" {if...}<C-j>            展开代码片段/跳到下一个占位符位置
" {if...}<C-k>            跳到上一个占位符位置
" qq<record>q @q          宏
" :A                      c++ .h .cpp转换
" ys/cs/gUs/vs/vss        edit search hit; press n and . to repeat
" :G                      git 信息(git diff + git blame)
" :%!xxd                  转为16进制文件

vim startuptime log

@bolun365
times in msec 
 clock   self+sourced   self:  sourced script
 clock   elapsed:              other lines

000.008  000.008: --- VIM STARTING ---
000.115  000.107: Allocated generic buffers
000.173  000.058: locale set
000.182  000.009: window checked
000.617  000.435: inits 1
000.694  000.077: parsing arguments
000.697  000.003: expanding arguments
000.711  000.014: shell init 
001.089  000.378: Termcap init 
001.120  000.031: inits 2
001.224  000.104: init highlight
025.493  023.881  023.881: sourcing /usr/local/share/vim/vim74/filetype.vim
025.633  000.050  000.050: sourcing /usr/local/share/vim/vim74/ftplugin.vim
025.777  000.064  000.064: sourcing /usr/local/share/vim/vim74/indent.vim
026.202  000.217  000.217: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
026.328  000.408  000.191: sourcing /usr/local/share/vim/vim74/syntax/synload.vim
026.374  000.523  000.115: sourcing /usr/local/share/vim/vim74/syntax/syntax.vim
027.179  000.196  000.196: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
030.153  002.014  002.014: sourcing /data/home/beck.zhang/.vim/autoload/plug.vim
034.649  000.506  000.506: sourcing /usr/local/share/vim/vim74/ftoff.vim
036.460  000.105  000.105: sourcing /data/home/beck.zhang/.vim/plugged/vim-go/ftdetect/gofiletype.vim
036.854  000.048  000.048: sourcing /data/home/beck.zhang/.vim/plugged/vim-gocode/ftdetect/gofiletype.vim
062.502  023.674  023.674: sourcing /usr/local/share/vim/vim74/filetype.vim
062.655  000.016  000.016: sourcing /usr/local/share/vim/vim74/ftplugin.vim
062.790  000.013  000.013: sourcing /usr/local/share/vim/vim74/indent.vim
062.927  061.557  010.467: sourcing $HOME/.vimrc
062.937  000.156: sourcing vimrc file(s)
063.729  000.594  000.594: sourcing /data/home/beck.zhang/.vim/plugged/L9/autoload/l9.vim
063.934  000.866  000.272: sourcing /data/home/beck.zhang/.vim/plugged/L9/plugin/l9.vim
064.768  000.722  000.722: sourcing /data/home/beck.zhang/.vim/plugged/mark/plugin/mark.vim
064.968  000.085  000.085: sourcing /data/home/beck.zhang/.vim/plugged/ag.vim/plugin/ag.vim
065.763  000.696  000.696: sourcing /data/home/beck.zhang/.vim/plugged/taglist.vim/plugin/taglist.vim
067.331  001.456  001.456: sourcing /data/home/beck.zhang/.vim/plugged/bufexplorer/plugin/bufexplorer.vim
075.065  007.565  007.565: sourcing /data/home/beck.zhang/.vim/plugged/vim-easymotion/plugin/EasyMotion.vim
079.853  004.648  004.648: sourcing /data/home/beck.zhang/.vim/plugged/The-NERD-Commenter/plugin/NERD_commenter.vim
080.313  000.099  000.099: sourcing /usr/local/share/vim/vim74/plugin/getscriptPlugin.vim
080.760  000.404  000.404: sourcing /usr/local/share/vim/vim74/plugin/gzip.vim
081.038  000.237  000.237: sourcing /usr/local/share/vim/vim74/plugin/matchparen.vim
081.756  000.679  000.679: sourcing /usr/local/share/vim/vim74/plugin/netrwPlugin.vim
081.839  000.021  000.021: sourcing /usr/local/share/vim/vim74/plugin/rrhelper.vim
081.924  000.043  000.043: sourcing /usr/local/share/vim/vim74/plugin/spellfile.vim
082.207  000.238  000.238: sourcing /usr/local/share/vim/vim74/plugin/tarPlugin.vim
082.387  000.130  000.130: sourcing /usr/local/share/vim/vim74/plugin/tohtml.vim
082.661  000.209  000.209: sourcing /usr/local/share/vim/vim74/plugin/vimballPlugin.vim
083.016  000.280  000.280: sourcing /usr/local/share/vim/vim74/plugin/zipPlugin.vim
083.069  001.754: loading plugins
083.079  000.010: inits 3
083.324  000.245: reading viminfo
083.345  000.021: setting raw mode
083.360  000.015: start termcap
083.391  000.031: clearing screen
085.938  000.140  000.140: sourcing /usr/local/share/vim/vim74/ftplugin/c.vim
086.234  000.853  000.713: sourcing /usr/local/share/vim/vim74/ftplugin/cpp.vim
086.731  000.033  000.033: sourcing /usr/local/share/vim/vim74/indent/cpp.vim
090.132  002.874  002.874: sourcing /usr/local/share/vim/vim74/syntax/c.vim
090.345  003.263  000.389: sourcing /usr/local/share/vim/vim74/syntax/cpp.vim
091.912  004.372: opening buffers
092.011  000.099: BufEnter autocommands
092.014  000.003: editing files in windows
098.020  006.006: VimEnter autocommands
098.023  000.003: before starting main loop
103.601  005.578: first screen update
103.605  000.004: --- VIM STARTED ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值