介紹一些關於Gvim(windows 7 32位 Vim 7.4)的基本配置,除了特別說明,代碼一概添加在安裝目錄下的_vimrc文件中。vim
一、取消自動備份,這行代碼須要添加在 _vimrc文件中的behave mswin以後才能生效:windows
set nobackup
二、F4一鍵添加做者信息: app
map <F4> :call TitleDet()<cr>'s function AddTitle() call append(0,"/*============================================================================") call append(1,"* Author : vitah") call append(2,"* Mail : linw1225@163.com") 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 None endf "更新最近修改時間和文件名 function UpdateTitle() normal m' "" execute '/* Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@' execute '/* Last modified :/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@' normal '' normal mk execute '/* Filename :/s@:.*$@\=": ".expand("%:t")@' execute "noh" normal 'k echohl WarningMsg | echo "Successful in updating the copy right." | echohl None endfunction "判斷前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
三、自動完成括號引號:ide
: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>i function ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif end
四、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 "! %<" endif endfunc
五、其他常規設置:ui
" ============================================================================ " ============================================================================ " 常規配置 " ============================================================================ " ============================================================================ 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
" ============================================================================ " ============================================================================ " 自動添加做者信息設置 " ============================================================================ " ============================================================================ map <F4> :call AddTitle()<cr> function AddTitle() call append(0,"// Copyright 2014 Blueant Inc. All Rights Reserved.") call append(1,"") call append(2,"/**") call append(3," * @created ".strftime("%Y/%m/%d")) call append(4," * @filename ".expand("%:t")) call append(5," * @author linw1225@163.com(vitah)") call append(6," * @fileoverview") call append(7," */") echohl WarningMsg | echo "Successful in adding the copyright." | echohl None endf