Gvim一些基本配置

來源:互聯網
上載者:User

標籤: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 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.