编辑vim配置文件,使新建文件自动写入文件头
因工作需要经常写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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |