在使用shell编程时,每次打开新的脚本都需要在开头输入
#!/bash/bin 创建时间、创建人、联系方式等参数,每次都输入较为繁琐,因此可以在可以设置默认的配置文件,这样每次在启动时就可以自动配置好相关信息。
配置步骤:
在根目录下新建个
[root@eric ~]# vim .vimrc
在此vimrc中插入下面的代码:
1 set ignorecase
2 set cursorline
3 set autoindent
4 autocmd BufNewFile *.sh exec ":call SetTitle()"
5 func SetTitle()
6 if expand("%:e") == 'sh'
7 call setline(1,"#!/bin/bash")
8 call setline(2,"#")
9 call setline(3,"#********************************************************************")
10 call setline(4,"#Author: zhangsan")
11 call setline(5,"#QQ: 12345678")
12 call setline(6,"#Date: ".strftime("%Y-%m-%d"))
13 call setline(7,"#FileName: ".expand("%"))
14 call setline(8,"#URL: http://www.baidu.com")
15 call setline(9,"#Description: The test script")
16 call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
17 call setline(11,"#********************************************************************")
18 call setline(12,"")
19 endif
20 endfunc
21 autocmd BufNewFile * normal G
至此,以后每次打开新建的shell脚本,都会出现默认的设置格式,极大的节省了时间。