vimrc配置汇总(win版)

Posted 哥斯达黎加

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vimrc配置汇总(win版)相关的知识,希望对你有一定的参考价值。

-------------------------------------------- 2106-06-21 11:52:00 --------------------------------------------

" 设置编码
set encoding=utf-8
set langmenu=zh_CN.UTF-8 "set menu‘s language of gvim. no spaces beside ‘=‘
language messages en_US.UTF-8 "zh_CN.utf-8

"   ---------------------- 系统自带设置 -------------------------
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
  let opt = -a --binary 
  if &diffopt =~ icase | let opt = opt . -i  | endif
  if &diffopt =~ iwhite | let opt = opt . -b  | endif
  let arg1 = v:fname_in
  if arg1 =~   | let arg1 = " . arg1 . " | endif
  let arg2 = v:fname_new
  if arg2 =~   | let arg2 = " . arg2 . " | endif
  let arg3 = v:fname_out
  if arg3 =~   | let arg3 = " . arg3 . " | endif
  let eq = ‘‘
  if $VIMRUNTIME =~  
    if &sh =~ \<cmd
      let cmd = "" . $VIMRUNTIME . \diff"
      let eq = "
    else
      let cmd = substitute($VIMRUNTIME,  , " , ‘‘) . \diff"
    endif
  else
    let cmd = $VIMRUNTIME . \diff
  endif
  silent execute ! . cmd .   . opt . arg1 .   . arg2 .  >  . arg3 . eq
endfunction

if has("gui_running")
    "标签页栏中去除当前所编辑文件的路径信息,只保留文件名
function ShortTabLabel ()
    let bufnrlist = tabpagebuflist (v:lnum)
    let label = bufname (bufnrlist[tabpagewinnr (v:lnum) -1])
    let filename = fnamemodify (label, :t)
    return filename
endfunction
set guitablabel=%{ShortTabLabel()}
endif


"------------------- vim基础设置 --------------------------
set nu
set hlsearch
set tabstop=4
set expandtab
set shiftwidth=4
set autoindent
set hidden                " 避免当前编辑文档未保存时,在新窗口打开文档
set ignorecase
set cursorline 
"set textwidth=80
set colorcolumn=81
set mouse=a
set completeopt=menu     " 补全设置
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)
set statusline=%4n%m\ %1*>\ %*%t%1*\ <%*\ %<%h%w%q%r%F%=%l,\ %c\ :\ %p%%%1*\|%*0x%02B%1*\|%*%{&fileformat}%1*\|%*%{&encoding}
"hi myhl guibg=#ff0000
set nobackup
set noundofile
set noswapfile
set laststatus=2
"set nowrap  " 不拆行
set fdm=syntax  " 代码折叠方式
set nofoldenable " 启动时关闭折叠
"set syntax enable
if has("gui_running")   "如果在 GUI 环境下运行则设置下面语句 
    set guifont=Consolas:h12
    "set guifont=Dejavu\ Sans\ Mono:h10
    set guioptions-=T   " 不显示工具栏
    set guioptions-=L   " 不显示左边滚动条
    set guioptions-=r   " 不显示右边滚动条
    set guioptions-=m 
    set vb t_vb=        " 禁用响铃提醒
    au GuiEnter * set t_vb=
    "hi SpecialKey guifg=BG 
endif

if has("win32")
    au GuiEnter * simalt ~x
endif


" --------------------------设置 常用快捷键--------------------------------
function DeleteCurBuf()
    let l:currentBufNum = bufnr("%")
    if 0 == buflisted(l:currentBufNum)
        exec "echo \‘This buffer can not delete.\‘"
        return
    endif
    exec "bn"
    let l:newBufNum = bufnr("%")
    if l:currentBufNum == l:newBufNum
        exec "echo \‘This is the last opened file.\‘"
        return
    endif
    exec "bw " . l:currentBufNum
endfunction
nmap Q :call DeleteCurBuf()<cr>
nmap <leader>q :q<CR>
nmap <leader>b :ls<CR>
nmap <leader>n :nohl<CR>
nmap <leader>w :update<CR>
nmap <leader>W :wa<CR>
nmap <leader>e :browse confirm e<CR>
"nmap <leader>s :e $VIM/_vimrc<CR>
nmap <leader>s :e c:/users/10171103/_vimrc<CR>
nmap <leader>c :cd 

"let g:EasyMotion_leader_key = ‘;‘
nmap ;s <Plug>(easymotion-F)
nmap ;f <Plug>(easymotion-f)
nmap ;j <Plug>(easymotion-j)
nmap ;k <Plug>(easymotion-k)

nmap <C-d><c-d> :pwd<CR>
nmap <c-d><c-s> :cd ..<CR>:pwd<CR>
nmap <c-s-tab> :tabn<cr>
nmap <c-l> :tab split<cr>
nmap <c-k> :tabc<cr>

nmap <S-Tab> <ESC>:bn<CR>
vmap <S-Tab> <ESC>:bn<CR>
imap <S-Tab> <ESC>:bn<CR>
nmap <C-Tab> <ESC>:b#<CR>
vmap <C-Tab> <ESC>:b#<CR>
imap <C-Tab> <ESC>:b#<CR>
map <c-w>, <esc>:vertical resize +3<cr>
map <c-w>. <esc>:vertical resize -3<cr>

function WasCommented(str)
    let len = strlen(a:str)
    let i = 0
    while i < len
        if a:str[i] !=   || a:str[i] != "\t"
            break
        endif
        let i += 1
    endwhile
    if i < len - 1 && a:str[i] == a:str[i+1] && a:str[i] == "/"
        return 1
    else
        return 0
    endif
endfunction
function ToggleCommentLine()
    let nr = line(.)
    let str_line = getline(nr)
    if WasCommented(str_line)
        let newstr = substitute(str_line, //, ‘‘, ‘‘)
    else
        let newstr = substitute(str_line, ^, //, ‘‘)
    endif
    :call setline(nr, newstr)
endfunction

nmap <f5> <esc>:call ToggleCommentLine()<cr>
imap <f5> <esc>:call ToggleCommentLine()<cr>
vmap <f5> <esc>:call ToggleCommentLine()<cr>

" 1 tagbar打开了,2 nerdtree打开了,3都打开了,0都没打开
function WhichOpened()
    let returnValue = 0
    if bufwinnr(__Tagbar__) != -1
        let returnValue += 1
    endif
    if bufwinnr(NERD_tree_1) != -1
        let returnValue += 2
    endif
    return returnValue
endfunction
function SwitchTagbarNERDTree()
    let tmp = WhichOpened()
    exec "NERDTreeClose"
    if (tmp != 1) && (tmp != 3)
        exec "TagbarOpen"
    else
        exec "TagbarClose"
        exec "NERDTreeToggle"
        exec "normal! \<c-w>l"
    endif
endfunction

let s:lastTNStatus = 1
function OpenCloseTagbarNERDTree()
    let currTNStatus = WhichOpened()
    exec "NERDTreeClose"
    if currTNStatus != 0
        exec "TagbarClose"
        let s:lastTNStatus = currTNStatus
    elseif s:lastTNStatus == 1
        exec "TagbarOpen"
    else
        exec "TagbarClose"
        exec "NERDTreeToggle"
        exec "normal! \<c-w>l"
    endif
endfunction

nmap <f1> <esc>:call OpenCloseTagbarNERDTree()<cr>
vmap <f1> <esc>:call OpenCloseTagbarNERDTree()<cr>
imap <f1> <esc>:call OpenCloseTagbarNERDTree()<cr>
nmap <f2> <esc>:call SwitchTagbarNERDTree()<cr>
vmap <f2> <esc>:call SwitchTagbarNERDTree()<cr>
imap <f2> <esc>:call SwitchTagbarNERDTree()<cr>
"nmap <F1> <esc>:NERDTreeClose<cr>:TagbarOpen<cr>
"vmap <F1> <esc>:NERDTreeClose<cr>:TagbarOpen<cr>
"imap <F1> <esc>:NERDTreeClose<cr>:TagbarOpen<cr>
"nmap <F2> <esc>:TagbarClose<cr>:NERDTreeClose<cr>:NERDTreeToggle<cr>
"vmap <F2> <esc>:TagbarClose<cr>:NERDTreeClose<cr>:NERDTreeToggle<cr>
"imap <F2> <esc>:TagbarClose<cr>:NERDTreeClose<cr>:NERDTreeToggle<cr>
nmap <c-f9> :NERDTreeFind<cr>
vmap <F3>  <C-C><ESC>/<C-R>+<CR><ESC>
nmap <F3> <ESC>/<C-R>=expand("<cword>")<CR><CR>
imap <F3> <ESC>/<C-R>=expand("<cword>")<CR><CR>
nmap <F4> <ESC>:Grep 
vmap <F4> <ESC>:Grep 
imap <F4> <ESC>:Grep 
"nmap <F5> <ESC>:NERDTreeClose<cr>:TagbarClose<cr>
"vmap <F5> <ESC>:NERDTreeClose<cr>:TagbarClose<cr>
"imap <F5> <ESC>:NERDTreeClose<cr>:TagbarClose<cr>
nmap <F6> <ESC>:CtrlPFunky<cr>
vmap <F6> <ESC>:CtrlPFunky<cr>
imap <F6> <ESC>:CtrlPFunky<cr>
nnoremap <silent> <F11> <ESC>:<C-R>=line("‘<")<CR>,<C-R>=line("‘>")<CR>s/^/\/\/<CR>/^$x<CR>
vnoremap <silent> <F11> <ESC>:<C-R>=line("‘<")<CR>,<C-R>=line("‘>")<CR>s/^/\/\/<CR>/^$x<CR>
inoremap <silent> <F11> <ESC>:<C-R>=line("‘<")<CR>,<C-R>=line("‘>")<CR>s/^/\/\/<CR>/^$x<CR>
nnoremap <silent> <F12> <ESC>:<C-R>=line("‘<")<CR>,<C-R>=line("‘>")<CR>s/\/\//<CR>/^$x<CR>
vnoremap <silent> <F12> <ESC>:<C-R>=line("‘<")<CR>,<C-R>=line("‘>")<CR>s/\/\//<CR>/^$x<CR>
inoremap <silent> <F12> <ESC>:<C-R>=line("‘<")<CR>,<C-R>=line("‘>")<CR>s/\/\//<CR>/^$x<CR>

function FindFilePath()
    exec TagbarClose
    exec NERDTreeFind
    exec "normal! \<c-w>l"
endfunction
nmap <f9> <esc>call FindFilePath()<cr>
vmap <f9> <esc>call FindFilePath()<cr>
imap <f9> <esc>call FindFilePath()<cr>

function IsQuickfixLoaded()
    redir => bufoutput
    exe "silent! buffers!"
    " This echo clears a bug in printing that shows up when it is not present
    silent! echo ""
    redir END
    return match(bufoutput, "\"\\[Quickfix List\\]\"", 0, 0) != -1
endfunction
function ToggleQuickfix()
    if IsQuickfixLoaded()
        :ccl
        :exec "normal! \<c-w>l"
    else
        :copen
        :exec "normal! \<c-w>J"
    endif
endfunction
nmap <F10> <ESC>:call ToggleQuickfix()<CR>
vmap <F10> <ESC>:call ToggleQuickfix()<CR>
imap <F10> <ESC>:call ToggleQuickfix()<CR>
nnoremap <F7> <ESC>:CtrlP<CR>
vnoremap <F7> <ESC>:CtrlP<CR>
inoremap <F7> <ESC>:CtrlP<CR>
nmap <F8> <ESC>:CtrlPBuffer<CR>
vmap <F8> <ESC>:CtrlPBuffer<CR>
imap <F8> <ESC>:CtrlPBuffer<CR>

" -----------------------------------设置各插件-------------------------------------
" Bundle
filetype off
" 设置vundle路径
set rtp+=$VIM/vimfiles/bundle/vundle/
call vundle#rc(‘$VIM/vimfiles/bundle/‘)  
Bundle gmarik/vundle
 
"Bundle ‘altercation/vim-colors-solarized‘
Bundle molokai
"Bundle ‘ciaranm/inkpot‘
"Bundle ‘Lokaltog/vim-powerline‘
"Bundle ‘vim-airline/vim-airline‘
"Bundle ‘vim-airline/vim-airline-themes‘
Bundle majutsushi/tagbar
Bundle scrooloose/nerdtree
Bundle ervandew/supertab
"Bundle ‘yegappan/grep‘
Bundle dkprice/vim-easygrep
Bundle easymotion/vim-easymotion
Bundle kien/ctrlp.vim
Bundle tacahiroy/ctrlp-funky
Bundle drmingdrmer/xptemplate
Bundle vim-scripts/jsbeautify
"Bundle ‘othree/xml.vim‘
"Bundle ‘Valloric/YouCompleteMe‘
"Bundle ‘vim-scripts/javacomplete‘
"Bundle ‘artur-shaik/vim-javacomplete2‘
"Bundle ‘vim-scripts/OmniCppComplete‘
filetype plugin indent on

" grep
"let Grep_Find_Path = ‘"C:\Program Files\Git\usr\bin\find.exe"
"let Grep_Path = ‘"C:\Program Files\Git\usr\bin\grep.exe"
"let Grep_Xargs_Path = ‘"C:\Program Files\Git\usr\bin\xargs.exe"
"let Grep_Default_Options = ‘-i -r --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.c" --include="*.cc" --include="*.java"
"let Grep_Default_Filelist = ‘.‘

" EasyGrep
let g:EasyGrepMode=2 " use TrackExt
let g:EasyGrepReplaceWindowMode=2 "autowriteall; create no new windows (when replace)
let g:EasyGrepJumpToMatch=0
let g:EasyGrepAllOptionsInExplorer=1
"let g:EasyGrepRoot="search:.git,.svn,.root"
set grepprg=grep\ -n\ -a
let g:EasyGrepCommand=1
let g:EasyGrepRecursive=1
let g:EasyGrepSearchCurrentBufferDir=0
let g:EasyGrepFilesToExclude=.svn,.git,.root,bin,target,*.swp

" 设置supertab
let g:SuperTabDefaultCompletionType="context"
let g:SuperTabMappingForward = <s-tab>
let g:SuperTabMappingBackward = <tab>


" 设置Tagbar
let g:tagbar_left=1
"let g:tagbar_width=30
let g:tagbar_autoclose=0
"let g:tagbar_sort = 0
let g:tagbar_compact = 1
"let g:tagbar_show_linenumbers = 2

" NERDTree
"let NERDTreeWinPos=‘right‘
let NERDTreeShowLineNumbers=0
let NERDTreeWinSize=40

" 设置 cscope
if has("cscope")
    set csprg=cscope
    set csto=0
    set cst
    set cscopequickfix=s-,g-,c-,f-,d-,i-,t-,e-
    set nocsverb
    set csverb
    "nmap zs :cs find s <C-R>=expand("<cword>")<CR><CR>
    map <C-g><C-g> :cs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-G><C-C> :cs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-G><C-T> :cs find t <C-R>=expand("<cword>")<CR><CR>
    vmap <C-G><C-T> <ESC>:cs find t <C-R>=expand("<cword>")<CR><CR>
    imap <C-G><C-T> <ESC>:cs find t <C-R>=expand("<cword>")<CR><CR>
    "nmap ze :cs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-G><C-f> :cs find f <C-R>=expand("<cword>")<CR><CR>
    "nmap zi :cs find i ^<C-R>=expand("<cword>")<CR>$<CR>
    "nmap zd :cs find d <C-R>=expand("<cword>")<CR><CR>
endif

" 设置 ctrlp
"let g:ctrlp_map = ‘‘   " 去掉ctrl+p快捷键
let g:ctrlp_cmd=CtrlPBuffer
let g:ctrlp_working_path_mode = rw
let g:ctrlp_by_filename = 1
let g:ctrlp_max_height = 30
let g:ctrlp_max_files = 50000
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_cache_dir = $VIM./cache/ctrlp
" 手动指定搜索的根目录let g:ctrlp_root_markers = [‘‘]
let g:ctrlp_root_markers = [.root]  " set my root marker for ctrlp
"let g:ctrlp_custom_ignore = ‘\v[\/](build|bin|src\\win32)$‘
let g:ctrlp_custom_ignore = {
    \ dir: \v[\/](build|bin|target)$,
    \ file: \v\.(jar|class)$,
    \ link: SOME_BAD_SYMBOLIC_LINKS,}

let g:ctrlp_extensions = [funky]
let g:ctrlp_funky_syntax_highlight = 1

"set bg=light
"colorscheme solarized
"colorscheme desert
"let g:molokai_original=1
colorscheme molokai 
"colorscheme inkpot

"let g:Powerline_colorscheme=‘solarized256‘
"let g:Powerline_colorscheme=‘default‘
"let g:Powerline_stl_path_style = ‘full‘
"let g:airline#extensions#disable_rtp_load = 1
"let g:airline_section_error = ""
"let g:airline_section_warning = ""
"let g:airline_detect_modified=0

"
" vim-javacomplete2
"autocmd FileType java setlocal omnifunc=javacomplete#Complete

 

the end.

以上是关于vimrc配置汇总(win版)的主要内容,如果未能解决你的问题,请参考以下文章

vim代码片段插件ultisnips的使用

Windows 下vim的配置文件_vimrc

mac中如何修改vimrc?

Windows下,Vim的配置文件(_vimrc)在哪?

[vscode]--HTML代码片段(基础版,reactvuejquery)

vim基本操作