Gvim一些基本配置

  介绍一些关于Gvim(windows 7 32位 Vim 7.4)的基本配置,除了特别说明,代码一律添加在安装目录下的_vimrc文件中。

1、取消自动备份,这行代码需要添加在 _vimrc文件中的behave mswin之后才能生效:

set nobackup

 2、F4一键添加作者信息: 

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(":	%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*Lastsmodified :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>i
function ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "<Right>"
    else
        return a:char
    endif
end
自动完成括号引号

 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 "! %<"
        endif
endfunc
一键编译运行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 
 
6、添加作者信息(另外格式):
" ============================================================================
" ============================================================================
"                               自动添加作者信息设置
" ============================================================================
" ============================================================================
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
View Code
原文地址:https://www.cnblogs.com/vitah/p/3820022.html