首页 > 代码库 > Gvim一些基本配置

Gvim一些基本配置

  介绍一些关于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          : 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 Noneendf"更新最近修改时间和文件名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 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