因工作需要经常写shell脚本,每次都要写脚本的头,就想偷个懒,在每次写脚本的时候可以自动生成想要的信息,编辑/etc/vimrc该文件,在新增.sh文件的时候会出现一些信息
autocmd BufNewFile *.sh exec ":call Setcomment()"
func Setcomment()
call append(0,"#!/bin/bash")
call append(1,"#*********************************** ")
call append(2,"#* copyleft test " .strftime("%Y-%m-%d"))
call append(3,"#* scriptname: " .expand("%"))
call append(4,"#* email: sb@localhost")
call append(5,"#* version: v0.1 ")
call append(6,"#*********************************** ")
endfunc
=================================================================================================================================================================================================================================
编辑/etc/vimrc该文件,在新增.sh以及.py文件的时候会出现一些信息
autocmd BufNewFile *.py,*.sh,exec ":call SetTitle()"
let $author_name = "xxx"
let $author_email = "xxx@xxx.xxx"
func SetTitle()
if &filetype == 'sh'
call setline(1,"\###################################################################")
call append(line("."),"\# File Name: ".expand("%"))
call append(line(".")+1,"\# Author: ".$author_name)
call append(line(".")+2,"\# mail: ".$author_email)
call append(line(".")+3,"\# Created Time: ".strftime("%c"))
call append(line(".")+4,"\#=============================================================")
call append(line(".")+5,"\#!/bin/bash")
call append(line(".")+6,"")
else
call setline(1,"\#!/usr/bin/python")
call append(line(".")+6,"")
endif
endfunc
原文链接:https://www.f2er.com/bash/392269.html