01-vim编辑器自动添加作者时间等前缀信息

 在ubuntu的家目录下执行命令: gedit .vimrc
 将下面代码修改为自己的信息后粘贴到最后保存即可。

set nu
set nocp
set tabstop=4
set softtabstop=4
set shiftwidth=4
set noexpandtab
syntax on
map <F7> :call FileHead()<CR>5k
function FileHead()
	call append( 0,"/***************************************************")
	call append( 1,"## filename      : ".expand("%:t")                   )
	call append( 2,"## author        : xiaoming                         ")
	call append( 3,"## e-mail        : xiaoming@163.com                 ")
	call append( 4,"## create time   : ".strftime("%Y-%m-%d %H:%M:%S")   )
	call append( 5,"## last modified : ".strftime("%Y-%m-%d %H:%M:%S")   )
	call append( 6,"## description   : NA                               ")
	call append( 7,"***************************************************/")
	call append( 8,"#include <stdio.h>                                  ")
	call append( 9,"#include <stdlib.h>                                 ")
	call append(10,"#include <string.h>                                 ")
	call append(11,"                                                    ")
	call append(12,"int main(int argc, char *argv[])                    ")
	call append(13,"{                                                   ")
	call append(14,"                                                    ")
	call append(15,"	return 0;                                       ")
	call append(16,"}                                                   ")
	call append(17,"                                                    ")
	call append(18,"                                                    ")
	call append(19,"                                                    ")
	call append(20,"/***************************************************")
	call append(21,"输出结果:                                          ")
	call append(22,"                                                    ")
	call append(23,"***************************************************/")
	echo
	
endfunction

function SetLastModifiedTimes()
	let line = getline(5)
	let newtime = "## last modified : ".strftime("%Y-%m-%d %H:%M:%S")
	let repl = substitute(line,".*$",newtime,"g")
	let res = search("## last modified","w")
	if res
		call setline(5,repl)
	endif
endfunction
autocmd BufWrite *.c call SetLastModifiedTimes()

 测试方法:新建一个.c文件,进入后先按F7键,生成的注释如下图所示:
在这里插入图片描述
 可以依据自己的爱好对代码进行修改,其中 last modified 一行中前面的序号要与下面这两行的序号一致,这样才能对最近一次修改的时间进行更新。

call append( 5,"## last modified : ".strftime("%Y-%m-%d %H:%M:%S")   )
let line = getline(5)
...
call setline(5,repl)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值