Posted on 2008-09-20 14:28
T.S Liu 閱讀(1061)
評論(3) 編輯 收藏 引用 所屬分類:
vim/gvim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般設(shè)定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 設(shè)定默認解碼
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
" 不要使用vi的鍵盤模式,而是vim自己的
set nocompatible
" history文件中需要記錄的行數(shù)
set history=100
" 在處理未保存或只讀文件的時候,彈出確認
set confirm
" 與windows共享剪貼板
set clipboard+=unnamed
" 偵測文件類型
filetype on
" 載入文件類型插件
filetype plugin on
" 為特定文件類型載入相關(guān)縮進文件
filetype indent on
" 保存全局變量
set viminfo+=!
" 帶有如下符號的單詞不要被換行分割
set iskeyword+=_,$,@,%,#,-
" 語法高亮
syntax on
" 高亮字符,讓其不受100列限制
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%101v.*'
" 狀態(tài)行顏色
highlight StatusLine guifg=SlateBlue guibg=Yellow
highlight StatusLineNC guifg=Gray guibg=White
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件設(shè)置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 不要備份文件(根據(jù)自己需要取舍)
set nobackup
" 不要生成swap文件,當(dāng)buffer被丟棄的時候隱藏它
setlocal noswapfile
set bufhidden=hide
" 字符間插入的像素行數(shù)目
set linespace=0
" 增強模式中的命令行自動完成操作
set wildmenu
" 在狀態(tài)行上顯示光標(biāo)所在位置的行號和列號
set ruler
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
" 命令行(在狀態(tài)行下)的高度,默認為1,這里是2
set cmdheight=2
" 使回格鍵(backspace)正常處理indent, eol, start等
set backspace=2
" 允許backspace和光標(biāo)鍵跨越行邊界
set whichwrap+=<,>,h,l
" 可以在buffer的任何地方使用鼠標(biāo)(類似office中在工作區(qū)雙擊鼠標(biāo)定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 啟動的時候不顯示那個援助索馬里兒童的提示
set shortmess=atI
" 通過使用: commands命令,告訴我們文件的哪一行被改變過
set report=0
" 不讓vim發(fā)出討厭的滴滴聲
set noerrorbells
" 在被分割的窗口間顯示空白,便于閱讀
set fillchars=vert:\ ,stl:\ ,stlnc:\
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮顯示匹配的括號
set showmatch
" 匹配括號高亮的時間(單位是十分之一秒)
set matchtime=5
" 在搜索的時候忽略大小寫
set ignorecase
" 不要高亮被搜索的句子(phrases)
set nohlsearch
" 在搜索時,輸入的詞句的逐字符高亮(類似firefox的搜索)
set incsearch
" 輸入:set list命令是應(yīng)該顯示些啥?
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
" 光標(biāo)移動到buffer的頂部和底部時保持3行距離
set scrolloff=3
" 不要閃爍
set novisualbell
" 我的狀態(tài)行顯示的內(nèi)容(包括文件類型和解碼)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
" 總是顯示狀態(tài)行
set laststatus=2
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自動格式化
set formatoptions=tcrqn
" 繼承前一行的縮進方式,特別適用于多行注釋
"set autoindent
" 為C程序提供自動縮進
set smartindent
" 使用C樣式的縮進
set cindent
" 制表符為4
set tabstop=4
" 統(tǒng)一縮進為4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 不要換行
set nowrap
" 在行和段開始處使用制表符
set smarttab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags的設(shè)定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 按照名稱排序
let Tlist_Sort_Type = "name"
" 在右側(cè)顯示窗口
let Tlist_Use_Right_Window = 1
" 壓縮方式
let Tlist_Compart_Format = 1
" 如果只有一個buffer,kill窗口也kill掉buffer
let Tlist_Exist_OnlyWindow = 1
" 不要關(guān)閉其他文件的tags
let Tlist_File_Fold_Auto_Close = 0
" 不要顯示折疊樹
let Tlist_Enable_Fold_Column = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 只在下列文件類型被偵測到的時候顯示行號,普通文本文件不顯示
if has("autocmd")
autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number
autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o/*<ESC>'>o*/
autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif " has("autocmd")
" F5編譯和運行C程序,F(xiàn)6編譯和運行C++程序
" 請注意,下述代碼在windows下使用會報錯
" 需要去掉./這兩個字符
" C的編譯和運行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"
endfunc
" C++的編譯和運行
map <F6> :call CompileRunGpp()<CR>
func! CompileRunGpp()
exec "w"
exec "!g++ % -o %<"
exec "! ./%<"
endfunc
" 能夠漂亮地顯示.NFO文件
set encoding=utf-8
function! SetFileEncodings(encodings)
let b:myfileencodingsbak=&fileencodings
let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
let &fileencodings=b:myfileencodingsbak
unlet b:myfileencodingsbak
endfunction
au BufReadPre *.nfo call SetFileEncodings('cp437')|set ambiwidth=single
au BufReadPost *.nfo call RestoreFileEncodings()
" 高亮顯示普通txt文件(需要txt.vim腳本)
au BufRead,BufNewFile * setfiletype txt
" 用空格鍵來開關(guān)折疊
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" minibufexpl插件的一般設(shè)置
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1