標籤:des style blog http color 使用
介紹一些關於Gvim(windows 7系統 Vim 7.4)的基本配置,除了特別說明,代碼一律添加在安裝目錄下的_vimrc檔案中。
1、取消自動備份:
set nobackup
2、F4一鍵添加作者資訊:
map <F4> :call TitleDet()<cr>‘sfunction AddTitle() call append(0,"/*============================================================================") call append(1,"* Author : vitah") call append(2,"* Mail : [email protected]") call append(3,"* Last modified : ".strftime("%Y-%m-%d %H:%M")) call append(4,"* Filename : ".expand("%:t")) call append(5,"* Description :") call append(6,"*") call append(7,"=============================================================================*/") echohl WarningMsg | echo "Successful in adding the copyright." | echohl Noneendf"更新最近修改時間和檔案名稱function UpdateTitle() normal m‘ "" execute ‘/* Last modified:/[email protected]:.*[email protected]\=strftime(":\t%Y-%m-%d %H:%M")@‘ execute ‘/* Last modified :/[email protected]:.*[email protected]\=strftime(": %Y-%m-%d %H:%M")@‘ normal ‘‘ normal mk execute ‘/* Filename :/[email protected]:.*[email protected]\=": ".expand("%:t")@‘ execute "noh" normal ‘k echohl WarningMsg | echo "Successful in updating the copy right." | echohl Noneendfunction"判斷前10行代碼裡面,是否有Last modified這個單詞,"如果沒有的話,代表沒有添加過作者資訊,需要新添加;"如果有的話,那麼只需要更新即可function TitleDet() let n=1 "預設為添加 while n < 8 let line = getline(n) if line =~ ‘^\*\s*\S*Last\smodified :\S*.*$‘ call UpdateTitle() return endif let n = n + 1 endwhile call AddTitle()endfunction添加作者資訊
3、自動完成括弧引號:
:inoremap ( ()<ESC>i:inoremap ) <c-r>=ClosePair(‘)‘)<CR>:inoremap { {}<ESC>i:inoremap } <c-r>=ClosePair(‘}‘)<CR>:inoremap [ []<ESC>i:inoremap ] <c-r>=ClosePair(‘]‘)<CR>"":inoremap < <><ESC>i"":inoremap > <c-r>=ClosePair(‘>‘)<CR>:inoremap " ""<ESC>i:inoremap ‘ ‘‘<ESC>i:inoremap ` ``<ESC>ifunction ClosePair(char) if getline(‘.‘)[col(‘.‘) - 1] == a:char return "\<Right>" else return a:char endifend自動完成括弧引號
4、F5一鍵編譯運行C/Cpp檔案:
" <F5> 編譯和運行C/C++map <F5> :call CompileRunGcc()<CR>func CompileRunGcc() exec "w" if &filetype == ‘c‘ echo "Compiling ..." exec "!gcc % -o %<" echo "Compiled successfully ..." exec "! %<" elseif &filetype == ‘cpp‘ echo "Compiling ..." exec "!g++ % -o %<" echo "Compiled successfully ..." exec "! %<" endifendfunc
一鍵編譯運行C/Cpp檔案
5、其餘常規設定:
" ============================================================================" ============================================================================" 常規配置" ============================================================================" ============================================================================ set fileencodings=utf-8,gbk "用於正常顯示中文注釋 set guifont=Courier_New:h11 "設定字型:大小如果字型中間有空格的話,用底線表示空格,如: "set guifont=Courier_New:h11 set number "顯示行號 set tabstop=4 "設定tab長度為4 set smarttab "行和段開始時使用定位字元 set shiftwidth=4 "縮排的空格數 set noexpandtab "是否在縮排和Tab鍵時使用空格代替 "使用noexpandtab取消設定 set smartindent set cindent set confirm "處理未儲存或唯讀檔案的時候,彈出確認 set shortmess=atI " 去掉歡迎介面 set mouse=n " 在所有模式下都允許使用滑鼠,還可以是n,v,i,c等 set showmatch "顯示括弧配對情況 set clipboard+=unnamed "與windows共用剪貼簿 set history=50 "keep 50 lines of command history set scrolloff=3 "游標移動到buffer的頂部和底部時保持3行距離 set laststatus=2 "啟用狀態列資訊 set cmdheight=2 "設定命令列的高度為2,預設為1 set cursorline "反白當前行 set nowrap "設定不自動換行 set autoread "當檔案在外部被修改,自動更新該檔案 set lines=33 columns=108 "設定視窗啟動時的大小 set writebackup "儲存檔案前建立備份,儲存成功後刪除該備份 set nobackup "設定無備份檔案 set backspace=2 "使回格鍵(backspace)正常處理indent, eol, start等 colorscheme evening "顏色配置 set nobackup "取消自動備份 filetype on filetype plugin on
View Code