shell 脚本自动插入文件头

时间:2024-11-24 13:35:37

vim编辑shell脚本自动插入文件头部信息,将下面的代码写入home目录xia .vimrc 文件即可。

shell 文件头:

1 autocmd BufNewFile *.sh exec ":call Setcomment()"
2 func Setcomment()
3 call append(0,"#!/bin/bash")
4 call append(1,"#*********************************** ")
5 call append(2,"#* time " .strftime("%Y-%m-%d"))
6 call append(3,"#* scriptname: " .expand("%"))
7 call append(4,"#* email: xx@126.com")
8 call append(5,"#*********************************** ")
9 endfunc

perl 文件头:

 1 autocmd BufNewFile *.pl exec ":call Setcomment_pl()"
2 func Setcomment_pl()
3 call append(0,"#!/bin/perl")
4 call append(1,"#*********************************** ")
5 call append(2,"#* time " .strftime("%Y-%m-%d"))
6 call append(3,"#* scriptname: " .expand("%"))
7 call append(4,"#* email: xx@126.com")
8 call append(5,"#*********************************** ")
9 call append(6,"use strict;")
10 call append(7,"use warnings;")
11 endfunc