“将键盘上的F4功能键映射为添加做者信息的快捷键vim
map <F4> ms:call TitleDet()<cr>'sapp
function AddTitle()this
call append(0,"/*******************************************************************************")spa
"call append(1,"#")orm
call append(1," * Author : YuanLu")ip
"call append(3,"#")get
call append(2," * Email : yuanlu837@gmail.com")it
"call append(5,"*")io
call append(3," * Last modified : ".strftime("%Y-%m-%d %H:%M"))ast
"call append(7,"#")
call append(4," * Filename : ".expand("%:t"))
"call append(9,"#")
call append(5," * Description : ")
""call append(11,"#")
call append(6," * *****************************************************************************/")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endf
"更新最近修改时间和文件名
normal m'
"execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
normal "
normal mk
"execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@'
execute "noh"
normal 'k
"echohl WarningMsg | echo "\n" | echo "Successful in updating the copy right."| echohl None
"endfunction
"判断前10行代码里面,是否有Last modified这个单词,
"若是没有的话,表明没有添加过做者信息,须要新添加;
"若是有的话,那么只须要更新便可
function TitleDet()
let n=1
while n < 10
let line = getline(n)
if line =~'^\#\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction
这段配置在Linux和window下都可正常运行。这样在一个C/C++/JAVA/C#的源代码里面,只须要按一下F4,就能够自动添加做者信息了。你们只须要修改上面这段配置关于做者信息的代码,就能够添加本身的信息了。
这是在我电脑上运行的结果,看一看,是否是很帅:
赶快动手吧,把这段配置添加到你的vimrc里,这样你就能够轻松地在源文件开始添加你的相关信息了,让咱们的代码更加规范。
/*!***********************************************************************
Function OutputInfo
description When prefOutputInfo is set to true this function outputs
various pieces of non-API dependent information via
PVRShellOutputDebug.
*************************************************************************/