2021-05-12 14:32:11
vim組態檔~/.vimrc
在啟動vim時,當前使用者根目錄下的.vimrc檔案會被自動讀取,該檔案可以包含一些設定甚至指令碼。
"設定編碼
set encoding=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set fileencodings=utf-8,ucs-bom,chinese
"語言設定
set langmenu=zh_CN.UTF-8
"設定語法高亮
syntax enable
syntax on
"設定配色方案
colorscheme torte
"可以在buffer的任何地方使用滑鼠
set mouse=a
set selection=exclusive
set selectmode=mouse,key
"高亮顯示匹配的括號
set showmatch
"去掉vi一致性
set nocompatible
"設定縮排
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent
set cindent
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif
"開啟檔案型別自動檢測功能
filetype on
"設定taglist
let Tlist_Show_One_File=0 "顯示多個檔案的tags
let Tlist_File_Fold_Auto_Close=1 "非當前檔案,函數列表折疊隱藏
let Tlist_Exit_OnlyWindow=1 "在taglist是最後一個視窗時退出vim
let Tlist_Use_SingleClick=1 "單擊時跳轉
let Tlist_GainFocus_On_ToggleOpen=1 "開啟taglist時獲得輸入焦點
let Tlist_Process_File_Always=1 "不管taglist視窗是否開啟,始終解析檔案中的tag
"設定WinManager外掛
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>
map <silent> <F9> :WMToggle<cr> "將F9系結至WinManager,即開啟WimManager
"設定CSCOPE
set cscopequickfix=s-,c-,d-,i-,t-,e- "設定是否使用quickfix視窗顯示cscope結果
"設定Grep外掛
nnoremap <silent> <F3> :Grep<CR>
"設定一鍵編譯
map <F6> :make<CR>
"設定自動補全
filetype plugin indent on "開啟檔案型別檢測
set completeopt=longest,menu "關掉智慧補全時的預覽視窗
"啟動vim時如果存在tags則自動載入
if exists("tags")
set tags=./tags
endif
"設定按F12就更新tags的方法
map <F12> :call Do_CsTag()<CR>
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<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>:copen<CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function Do_CsTag()
let dir = getcwd()
if filereadable("tags")
if(g:iswindows==1)
let tagsdeleted=delete(dir.""."tags")
else
let tagsdeleted=delete("./"."tags")
endif
if(tagsdeleted!=0)
echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
return
endif
endif
if has("cscope")
silent! execute "cs kill -1"
endif
if filereadable("cscope.files")
if(g:iswindows==1)
let csfilesdeleted=delete(dir.""."cscope.files")
else
let csfilesdeleted=delete("./"."cscope.files")
endif
if(csfilesdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
return
endif
endif
if filereadable("cscope.out")
if(g:iswindows==1)
let csoutdeleted=delete(dir.""."cscope.out")
else
let csoutdeleted=delete("./"."cscope.out")
endif
if(csoutdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
return
endif
endif
if(executable('ctags'))
"silent! execute "!ctags -R --c-types=+p --fields=+S *"
silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
endif
if(executable('cscope') && has("cscope") )
if(g:iswindows!=1)
silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.Java' -o -name '*.cs' > cscope.files"
else
silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
endif
silent! execute "!cscope -b"
execute "normal :"
if filereadable("cscope.out")
execute "cs add cscope.out"
endif
endif
endfunction
"設定預設shell
set shell=bash
"設定VIM記錄的歷史數
set history=400
"設定當檔案被外部改變的時侯自動讀入檔案
if exists("&autoread")
set autoread
endif
"設定ambiwidth
set ambiwidth=double
"設定檔案型別
set ffs=unix,dos,mac
"設定增量搜尋模式
set incsearch
"設定靜音模式
set noerrorbells
set novisualbell
set t_vb=
"不要備份檔案
set nobackup
set nowb
--------------------------------------分割線 --------------------------------------
把VIM打造成一個簡單實用的IDE http://www.linuxidc.com/Linux/2011-06/37032.htm
Vim學習指南 http://www.linuxidc.com/Linux/2013-08/89096.htm
快速學會 Vi編輯器 http://www.linuxidc.com/Linux/2013-08/88586.htm
強大的Vim 編輯器 http://www.linuxidc.com/Linux/2013-07/87544.htm
在CentOS 6.2上搭建Vim開發環境 http://www.linuxidc.com/Linux/2013-07/87363.htm
CentOS 5.4 安裝高亮Vim編輯工具 http://www.linuxidc.com/Linux/2013-06/86508.htm
Vim技巧分享:C語言設定 http://www.linuxidc.com/Linux/2012-12/77124.htm
Ubuntu中設定Vim的行號 http://www.linuxidc.com/Linux/2012-12/75485.htm
Vim編輯器使用基礎教學 http://www.linuxidc.com/Linux/2013-05/84031.htm
--------------------------------------分割線 --------------------------------------
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-07/119878.htm
相關文章