下面给大家分享一个shell脚本的模板文件,把它拷贝到用户的家目录下并命名成 .vimrc 名称,这样我们以后再次打开以 .sh结尾的文件时就会成自动生成一些注释信息,只要稍稍修改一下即可如图所示:
是不是很方便呢? 下面给大家分享一下代码,然后根据自己的需求将下面文件粘贴进去并进行根据自己的要求更改,保存退出就可以了。
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == ‘sh‘
call setline(1,"#!/bin/bash")
call setline(2,"#********************************************************************")
call setline(3,"#Author: Linuxidc.com")
call setline(4,"#Linux公社: www.linuxidc.com")
call setline(5,"#Date: ".strftime("%Y-%m-%d"))
call setline(6,"#FileName: ".expand("%"))
call setline(7,"#URL: https://www.linuxidc.com/Linux/2019-06/158912.htm")
call setline(8,"#Description: Annotated script")
call setline(9,"#********************************************************************")
call setline(10,"")
endif
endfunc
autocmd BufNewFile * normal G
第二个版本
[root@rabbitmq1 ~]# vim /root/.vimrc
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == ‘sh‘
call setline(1,"#!/bin/bash")
call setline(2,"#********************************************************************")
call setline(3,"#Author: Luojiaqi")
call setline(4,"#E-Mail: luojiaqi@yimaokeji.com")
call setline(5,"#Date: ".strftime("%Y-%m-%d"))
call setline(6,"#FileName: ".expand("%"))
call setline(7,"#URL: https://www.yimaokeji.com/")
call setline(8,"#Description: The test script")
call setline(9,"#********************************************************************")
call setline(10,"")
endif
endfunc
autocmd BufNewFile * normal G