vimrc文件:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般設定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 設定默認解碼
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
" 設置不與之前版本兼容
set nocompatible
" 查找結果高亮度顯示
set hlsearch
" 配色
colorscheme desert
" 顯示行號
set nu
" 檢測文件的類型
filetype on
" 設置當文件被改動時自動載入
set autoread
" 記錄歷史的行數
set history=80
" 設置語法高亮度
syntax on
" 在處理未保存或只讀文件的時候,彈出確認
set confirm
" 與windows共享剪貼板
set clipboard+=unnamed
" 載入文件類型插件
filetype plugin on
" 為特定文件類型載入相關縮進文件
filetype indent on
" 保存全局變量
set viminfo+=!
" 帶有如下符號的單詞不要被換行分割
set iskeyword+=_,$,@,%,#,-
" 設置鼠標一直可用
set mouse=a
" 高亮當前行
set cursorline
" 命令行高度
set cmdheight=1
" 啟動的時候不顯示那個援助索馬里兒童的提示
set shortmess=atI
" 設置幫助語言
if version >= 603
set helplang=cn
set encoding=utf-8
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件設置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 不要備份文件(根據自己需要取舍)
set nobackup
" 不要生成swap文件,當buffer被丟棄的時候隱藏它
setlocal noswapfile
set bufhidden=hide
" 字符間插入的像素行數目
set linespace=0
" 增強模式中的命令行自動完成操作
set wildmenu
" 在狀態行上顯示光標所在位置的行號和列號
set ruler
" 不讓vim發出討厭的滴滴聲
set noerrorbells
" 在被分割的窗口間顯示空白,便于閱讀
set fillchars=vert:\ ,stl:\ ,stlnc:\
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮顯示匹配的括號
set showmatch
" 不要高亮被搜索的句子(phrases)
"set nohlsearch
" 在搜索時,輸入的詞句的逐字符高亮(類似firefox的搜索)
set incsearch
" 搜索時忽略大小寫
set ignorecase
" 不要閃爍
set novisualbell
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自動格式化
set formatoptions=tcrqn
" 繼承前一行的縮進方式,特別適用于多行注釋
set autoindent
" 為C程序提供自動縮進
set smartindent
" 使用C樣式的縮進
set cindent
" 制表符為4
set tabstop=4
" 統一縮進為4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 設置每行80個字符自動換行
set textwidth=80
" -------------------------------------------------------------------------------------------------
" set mapleader
let mapleader = ","
" platform
function! MySys()
if has("win32")
return "windows"
else
return "linux"
endif
endfunction
" if file not opened, create a new tab, or switch to the opened file
function! SwitchToBuf(filename)
" find in current tab
let bufwinnr = bufwinnr(a:filename)
if bufwinnr != -1
exec bufwinnr . "wincmd w"
return
else
" search each tab
tabfirst
let tb = 1
while tb <= tabpagenr("$")
let bufwinnr = bufwinnr(a:filename)
if bufwinnr != -1
exec "normal " . tb . "gt"
exec bufwinnr . "wincmd w"
return
endif
tabnext
let tb = tb +1
endwhile
" not exist, new tab
exec "tabnew " . a:filename
endif
endfunction
" fast edit .vimrc
if MySys() == 'linux'
" fast reloading of the .vimrc
map <silent> <leader>ss :source ~/.vimrc<cr>
" fast editing of the .vimrc
map <silent> <leader>ee :call SwitchToBuf("~/.vimrc")<cr>
" when .vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc
elseif MySys() == 'windows'
" Set helplang
set helplang=cn
"Fast reloading of the _vimrc
map <silent> <leader>ss :source ~/_vimrc<cr>
"Fast editing of _vimrc
map <silent> <leader>ee :call SwitchToBuf("~/_vimrc")<cr>
"When _vimrc is edited, reload it
autocmd! bufwritepost _vimrc source ~/_vimrc
endif
if MySys() == 'windows'
source $VIMRUNTIME/mswin.vim
behave mswin
endif
" quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
nmap <leader>cn :cn<cr>
nmap <leader>cp :cp<cr>
nmap <leader>cw :cw 10<cr>
" vimgrep/lvimgrep(lv)
" 在當前文件中快速查找光標下的單詞, 并在窗口的位置列表中顯示
" 好像該功能有mark插件可以代勞:)
nmap <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr>
" omni completion(全能補全)
" 為支持C++的全能補全,需安裝插件: OmniCppComplete
" 并且生成tag文件的命令是(src為源文件目錄): ctags -R --c++-kinds=+p --fields=+iaS --extra=+q src
" 因為在對C++文件進行補全時,OmniCppComplete插件需要tag文件中包含C++的額外信息
" C++的補全連”CTRL-X CTRL-O“都不必輸入呵呵,測試通過
set completeopt=longest,menu " 只在下拉菜單中顯示匹配項目,并且會自動插入所有匹配項目的相同文本
inoremap <C-J> <C-X><C-O>
" generic completion(其他補全方式)
" 文件名補全
inoremap <C-F> <C-X><C-F>
" 宏定義補全
inoremap <C-D> <C-X><C-D>
" 整行補全
inoremap <C-L> <C-X><C-L>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags
set tags=tags " 當前目錄, 不知道為什么寫成./tags就無效
set tags+=../tags
" 為/usr/include目錄生成tags文件,缺點可能會導致自動完成的速度減慢,必要時去除
" 更好的辦法是需要時才加,例如/usr/include/gtk2.0/tags
" set tags+=/usr/include/tags
" Cscope
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>
" Tag List
" 按照名稱排序
let Tlist_Sort_Type = "name"
" 在右側顯示窗口
let Tlist_Use_Right_Window = 1
" 如果只有一個buffer,kill窗口也kill掉buffer
let Tlist_Exist_OnlyWindow = 1
" 使taglist只顯示當前文件tag,其它文件的tag都被折疊起來(同時顯示多個文件中的tag時)
let Tlist_File_Fold_Auto_Close = 1
" 不要顯示折疊樹
let Tlist_Enable_Fold_Column = 1
"不同時顯示多個文件的tag,只顯示當前文件的
let Tlist_Show_One_File = 1
" 鍵盤映射
nmap tl :TlistToggle<cr>
" Buf Explorer
let g:bufExplorerDefaultHelp=0 " Do not show default help.
let g:bufExplorerShowRelativePath=1 " Show relative paths.
let g:bufExplorerSortBy='mru' " Sort by most recently used.
let g:bufExplorerSplitRight=0 " Split left.
let g:bufExplorerSplitVertical=1 " Split vertically.
let g:bufExplorerSplitVertSize = 30 " Split width
let g:bufExplorerUseCurrentWindow=1 " Open in new window.
autocmd BufWinEnter \[Buf\ List\] setl nonumber
" Win Manager
let g:winManagerWindowLayout = "BufExplorer,FileExplorer|TagList"
let g:persistentBehaviour = 0
let g:winManagerWidth = 30
let g:defaultExplorer = 0
nmap <C-W><C-F> :FirstExplorerWindow<cr>
nmap <C-W><C-B> :BottomExplorerWindow<cr>
nmap wm :WMToggle<cr>
" Lookupfile
let g:LookupFile_MinPatLength = 2 "最少輸入2個字符才開始查找
let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
let g:LookupFile_PreservePatternHistory = 1 "保存查找歷史
let g:LookupFile_AlwaysAcceptFirst = 1 "回車打開第一個匹配項目
let g:LookupFile_AllowNewFiles = 0 "不允許創建不存在的文件
" 通過shell腳本: lookupfile_tag.sh生成當前目錄的filenametags文件
" 該腳本在~/.vim目錄下有備份
if filereadable("./filenametags") "設置tag文件的名字
let g:LookupFile_TagExpr = '"./filenametags"'
endif
nmap <silent> <leader>lk <Plug>LookupFile
nmap <silent> <leader>lb :LUBufs<cr>
nmap <silent> <leader>lw :LUWalk<cr>
" lookup file with ignore case
function! LookupFile_IgnoreCaseFunc(pattern)
let _tags = &tags
try
let &tags = eval(g:LookupFile_TagExpr)
let newpattern = '\c' . a:pattern
let tags = taglist(newpattern)
catch
echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
return ""
finally
let &tags = _tags
endtry
" Show the matches for what is typed so far.
let files = map(tags, 'v:val["filename"]')
return files
endfunction
let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'
" Mark
nmap <silent> <leader>hl <Plug>MarkSet
vmap <silent> <leader>hl <Plug>MarkSet
nmap <silent> <leader>hh <Plug>MarkClear
vmap <silent> <leader>hh <Plug>MarkClear
nmap <silent> <leader>hr <Plug>MarkRegex
vmap <silent> <leader>hr <Plug>MarkRegex
" SuperTab
" 記住上次的補全方式,直到按ESC退出插入模式為止
let g:SuperTabRetainCompletionType = 2
" 缺省的補全方式(設置為全能補全)
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
" DoxygenToolkit
let g:DoxygenToolkit_authorName="simplyzhao"
nmap da :DoxAuthor<cr>
nmap dx :Dox<cr>
nmap db :DoxBlock<cr>
posted on 2011-01-08 17:45
何克勤 閱讀(684)
評論(0) 編輯 收藏