编辑vimrc,使新建文件自动写入文件头

来源:互联网 发布:谓之知机什么意思 编辑:程序博客网 时间:2024/06/04 22:48

在创建脚本时,自动写入包含文件名、作者、邮箱、创建时间等信息的文件头。

这里只对.sh和.py文件进行自动写入设置。

打开vim配置文件

vim /etc/vimrc

加入如下代码
autocmd BufNewFile *.py,*.sh, exec ":call SetTitle()"let $author_name = "xxxx"let $author_email = "xxxx@xxx.xx"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, "")elsecall 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, "\#!/usr/bin/python")call append(line(".")+6, "")endifendfunc

保存退出后再创建脚本文件时就会自动写入信息头了


1 0
原创粉丝点击