加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

编辑vim配置文件,使新建文件自动写入文件头

发布时间:2020-12-15 16:46:18 所属栏目:安全 来源:网络整理
导读:因工作需要经常写shell脚本,每次都要写脚本的头,就想偷个懒,在每次写脚本的时候可以自动生成想要的信息,编辑/etc/vimrc该文件,在新增.sh文件的时候会出现一些信息 autocmd BufNewFile *.sh exec ":call Setcomment()" func Setcomment() call append(0,

因工作需要经常写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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读