介绍一些关于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