Shell-01-脚本开头实现自动添加注释

日常在编写脚本过程中,为了注明脚本用途,基本都会在开头填写基本注释,以备后续查看,但是每次都需要添加,总是效率很低,所以可以通过自动添加注释的方式实现,以下,是查阅资料后的实现方案:

vim .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: simba")
 call setline(4,"#Date: ".strftime("%Y-%m-%d"))
 call setline(5,"#Description: Annotated script")
 call setline(6,"#********************************************************************")
 call setline(7,"")
endif
endfunc
autocmd BufNewFile * normal G

如图:

然后退出保持即可。

测试一下:

vim test.sh

如图看效果:

 完美~

posted @ 2021-11-07 23:32  进阶的蜗牛  阅读(362)  评论(0编辑  收藏  举报