vim配置文件.vimrc

本文详细介绍了一套个性化的Vim配置方案,包括快捷键设置、文件类型配置、插件管理和自定义映射等,旨在提升开发效率和用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


" Update Log:
" V1:   Someday in 2009: Created and modified;
" V2:   2009,05,25: Update a shotkey to hide #ifdef Macro.
" V3:   2009,06,03: Update a function to control NERDTree with sigle
"           key; Update coding standadrd for Python.
" V3:   2009,06,04: Bind <F5> to run Bash, <F6> to run python.
" V4:   2009,06,05: Added some platform specific settings: fonts,
"           backups, and so on.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Required Plugins:
" C-support: Also known as c.vim, a powerful tool to write C/C++" code.
" NERDTree: A tool to explore local and network files and directories.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
" vi: set ts=4:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Judge whether it is Windows OS or not
let    s:MSWIN =   has("win16") || has("win32") || has("win64")

"Get out of VI's compatible mode..
set nocompatible

"Sets how many lines of history VIM har to remember
set history=100

"Enable filetype plugin
filetype plugin on
filetype indent on
syntax on

"Auto read a file when it has been changed by other program
set autoread

"Set mapleader
let mapleader = ","
let g:mapleader = ","
"C.vim mapleader
let g:C_MapLeader = ','

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
colorscheme desert
" Avoid clearing hilight definition in plugins
if !exists("g:vimrc_loaded")
    syntax enable

    " GUI settings
    if has("gui_running")
        set guioptions-=T
        set guioptions-=L
        set guioptions-=r
        set mouse=a
        if s:MSWIN
            set guifont=Consolas:h11
            colorscheme desert
        else
            set guifont=Consolas/ 11
            colorscheme darkblue
        endif
        nmap <silent><,p> :"+gp<cr>
        imap <silent><,p> :"+gp<cr>
        nmap <silent><,y> :"+gy<cr>
        imap <silent><,y> :"+gy<cr>
        nmap <C-a> gg V G
    else
    endif
endif

"Some nice mapping to switch syntax (useful if one mixes different languages in one file)
"Add more if needed
autocmd BufEnter * :syntax sync fromstart
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fileformats
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Favorite filetypes
set ffs=unix,dos
nmap <leader>fd :se ff=dos<cr>
nmap <leader>fu :se ff=unix<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" VIM userinterface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"Turn on WiLd menu
set wildmenu

"Always show current position
set ruler

"The commandbar is 1 high
set cmdheight=1

"Don't show line number
set nonu

"Do not redraw, when running macros.. lazyredraw
set lz

"Change buffer - without saving
set hid

"Set backspace
set backspace=eol,start,indent

"Bbackspace and cursor keys wrap to
"set whichwrap+=<,>,h,l
set whichwrap+=<,>

"Increase search mode
set incsearch

"Highlight search things
set hlsearch

"Set magic on
set magic

"No sound on errors.
set noerrorbells
set novisualbell

"show matching bracets
set showmatch

""""""""""""""""""""""""""""""
" Statusline
""""""""""""""""""""""""""""""
"Always hide the statusline
set laststatus=2

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" All about tabs
" ShortKey to change these settings can be found later.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"Tab configuration
set shiftwidth=4
set tabstop=4
set softtabstop=4
"Do use white spaces to fill the tabs.
set expandtab

"Disable winaltkeys to map Alt.
set winaltkeys=no

"set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
set cinoptions=:0,g0,t0,(0

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Abbrevs
" Usefull when typing frequently used words.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
abbr Yang YangYingchao
abbr yangying yangyingchao@gmail.com

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Editings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Delete the superflous white sapces
func! DeleteTrailingWS()
exe "normal mz"
%s//s/+$//ge
nohl
exe "normal `z"
endfunc

nmap <silent> <leader>ws :call DeleteTrailingWS()<cr>:w<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Restore cursor to file position in previous editing session
set viminfo='20,/"50,:20,n~/.viminfo
au BufReadPost * if line("'/"") > 0|if line("'/"") <= line("$")|exe("norm '/"")|else|exe "norm $"|endif|endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Session options
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set sessionoptions-=curdir
set sessionoptions+=sesdir

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Files and backups
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Turn backup off
set backup
set writebackup
set backupcopy=auto
set backupext=.bak
if s:MSWIN
    set backupdir=.
else
    set backupdir=~/.vim/backups/
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable folding, I find it very useful
"set fen
"set fdl=0
nmap <silent> <leader>zo zO
vmap <silent> <leader>zo zO

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text options
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set smarttab
"set lbr
set tw=72

""""""""""""""""""""""""""""""
" Indent
""""""""""""""""""""""""""""""
"Auto indent
set autoindent

"Smart indet
set si

"Wrap lines
set wrap
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
    set csprg=/usr/bin/cscope
    set csto=1
    set cst
    set nocsverb
" add any database in current directory
if filereadable("cscope.out")
      cs add cscope.out

endif
set csverb
endif

nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>h :cs help <CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   """"""""""""""""""""""""""""""
   " Taglist
   """"""""""""""""""""""""""""""
   nmap <silent><F8>        :Tlist<CR>:wincmd j<cr>
   imap <silent><F8>        :Tlist<CR>:wincmd j<cr>
   let Tlist_Use_Right_Window = 1
   let Tlist_Show_One_File = 1
   let Tlist_WinWidth = 27
   let Tlist_Exit_OnlyWindow = 1

   """"""""""""""""""""""""""""""
   " C-Support
   """"""""""""""""""""""""""""""
   "Mapleader was setted as ',' in previous setting.
   let g:C_LineEndCommColDefault = 45

   """"""""""""""""""""""""""""""
   " Calendar
   """"""""""""""""""""""""""""""
   "Mapleader was setted as ',' in previous setting.

   " NERDTree KeyBind
   let s:Dir_F = 0
   func! NERDTree_OC()
       exe "normal mz"
       if s:Dir_F
           let s:Dir_F = 0
           exe "1"
           exe "normal mz"
           exe "NERDTreeClose"
           exe ":wincmd j"
       else
           let s:Dir_F = 1
           exe "normal mz"
           exe "NERDTree"
       endif
   endfunc

   nmap <silent><F2> :call NERDTree_OC()<cr>

   """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   " Filetype generic
   """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   """"""""""""""""""""""""""""""
   " C/C++
   """""""""""""""""""""""""""""""
   autocmd FileType c,cpp map <buffer> <leader><space> :make<cr>
   autocmd FileType c,cpp setlocal cindent


   " Highlight space errors in C/C++ source files (Vim tip #935)
   if $VIM_HATE_SPACE_ERRORS != '0'
       let c_space_errors=1
   endif

   """"""""""""""""""""""""""""""
   " ANTLR
   """""""""""""""""""""""""""""""
   au BufRead,BufNewFile *.g set syntax=antlr3
   """"""""""""""""""""""""""""""
   " HTML related
   """"""""""""""""""""""""""""""
   " HTML entities - used by xml edit plugin
   let xml_use_xhtml = 1
   "let xml_no_auto_nesting = 1

   "To HTML
   let html_use_css = 1
   let html_number_lines = 0
   let use_xhtml = 1

   """""""""""""""""""""""""""""""
   " Vim section
   """""""""""""""""""""""""""""""
   autocmd FileType vim set nofen
   autocmd FileType vim map <buffer> <leader><space> :w!<cr>:source %<cr>

   """"""""""""""""""""""""""""""
   " HTML
   """""""""""""""""""""""""""""""
   au FileType html set ft=xml
   au FileType html set syntax=html

   """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   " Text file: using syntax plain to show all text files.
   """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   au BufRead,BufNewFile rfc*.* set syntax=plain
   au BufRead,BufNewFile RFC*.* set syntax=plain
   au BufRead,BufNewFile *.txt set syntax=plain
   au BufRead,BufNewFile *.text set syntax=plain
   au BufRead,BufNewFile draft* set syntax=plain
   au BufRead,BufNewFile DRAFT* set syntax=plain
   au BufRead,BufNewFile readme set syntax=plain
   au BufRead,BufNewFile README set syntax=plain
   au BufRead,BufNewFile *.srt set syntax=sts
   au BufRead,BufNewFile *.SRT set syntax=sts

   """"""""""""""""""""""""""""""
   " Tex
   """""""""""""""""""""""""""""""
   au BufRead,BufNewFile *.tex set dictionary+=/home/yyc/.vim/dictionary/tex.dic
   """"""""""""""""""""""""""""""
   " Python
   """""""""""""""""""""""""""""""
   au BufRead,BufNewFile *.py   setlocal tabstop=4
               / softtabstop=4
               / shiftwidth=4  
               / textwidth=72  
               / smarttab      
               / expandtab     
               / smarttab      
               / dictionary+=/home/yyc/.vim/dictionary/python.dicrtindent


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   "Quickfix
   nmap <leader>cn :cn<cr>
   nmap <leader>cp :cp<cr>
   nmap <leader>cw :cw 10<cr>
   "nmap <leader>cc :botright lw 10<cr>
   "map <c-u> <c-l><c-j>:q<cr>:botright cw 10<cr>

   function! s:GetVisualSelection()
       let save_a = @a
       silent normal! gv"ay
       let v = @a
       let @a = save_a
       let var = escape(v, '///.$*')
       return var
   endfunction

   " Fast grep
   nmap <silent> <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr>
   vmap <silent> <leader>lv :lv /<c-r>=<sid>GetVisualSelection()<cr>/ %<cr>:lw<cr>

   " Fast diff
   cmap @vd vertical diffsplit
   set diffopt+=vertical

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mark as loaded
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:vimrc_loaded = 1

" About Vimrc
"Fast reloading of the .vimrc
map <silent> <leader>sr :source ~/.vimrc<cr>
"Fast editing of .vimrc
map <silent> <leader>ee :e ~/.vimrc<cr>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Customized Key mapping
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"Case Sensitive or insensitive
map <silent> <leader>ic :set ic<cr>
map <silent> <leader>nic :set noic<cr>

"Fast saving
nmap <silent> <leader>ww :w<cr>
imap <silent> ,ww <Esc>:w<cr>
nmap <silent> <leader>wf :w!<cr>
nmap <silent> <leader>wa :wa<cr>

"Fast quiting
nmap <silent> <leader>xx :x<cr>
nmap <silent> <leader>xa :xa<cr>
nmap <silent> <leader>qq :x<cr>
nmap <silent> <leader>qa :xa<cr>

"Switch to current dir
map <silent> <leader>cd :cd %:p:h<cr>

"No heigh color
nmap <C-h> :noh<cr>

" Windows configuration
nmap <silent> <leader>w2 :split<cr>
nmap <silent> <leader>w3 :vs<cr>
nmap <silent> <leader>clo :close<cr>
nmap <silent> <leader>ol :only<cr>
"
"Buffer -- goto Next and Previous
map <leader>bn :bn<cr>
map <leader>bp :bp<cr>
map <C-k> :bn<cr>
map <C-j> :bp<cr>
map <C-l> zz

"Run Current Python script
nmap <leader>pr :!python %<cr>

" Make tags for ~/.vim/doc:
" I stored my rfc.txt in doc to quick reference.
nmap <leader>ht :helptags ~/.vim/doc<cr>

" Goto Table of Content(TOC)
nmap <leader>tc :ts TOC<cr> 1<cr>

" Merge Multiple empty lines into one line.
nmap <leader>db :g/^$/,/./j<cr>
nmap <leader>rb :g/^$/,/./-j<cr>

" Sort the
nmap <leader>st :%sort<cr>
vmap <leader>st :sort<cr>

" Display next tags and previous tags (when multiple types).
nmap <leader>tn :tn<cr>
nmap <leader>tp :tp<cr>
nmap <leader>mk :! mktags<cr>

" Enable of Disable Spell Check
nmap <leader>sp :set spell<cr>
nmap <leader>nsp :set nospell<cr>

" Hide #if defined(__KERNEL__)
func! HideIfdefine()
    exe "normal mz"
    g/#if.*[^!]KERNEL__)/?/.,/#else/-1 fold
    nohl
    exe "normal `z"
endfunc
nmap <leader>hi :call HideIfdefine()<cr>

" Load folds.
nmap <leader>lf :loadview<cr>

" Delete Repeated Lines and sort.
nmap <leader>dr :%sort u
vmap <leader>dr :sort u


" Shorkey to change tab configuration
nmap <leader>t8 :set shiftwidth=8 softtabstop=8 tabstop=8<cr>
nmap <leader>t4 :set shiftwidth=4 softtabstop=4 tabstop=4<cr>
nmap <leader>et :set expandtab<cr>
nmap <leader>nt :set noexpandtab<cr>

" Keybind to invoke Bash/Python
nmap <F5>   :!bash<cr>
nmap <F6>   :!python<cr>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值