脚本:
set nu
set ts=4
set expandtab
set ignorecase
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e")=='sh'
call setline(1,"#!/bin/bash")
call setline(2,"#")
call setline(3,"#*************************************************************")
call setline(4,"#Author: chen")
call setline(5,"#QQ: 2088346053")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#Description: The test script")
call setline(9,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(10,"#*************************************************************")
call setline(11,"")
endif
endfunc
autocmd BufNewFile * normal G"
单个用户有效,配置文件:~/.vimrc 若没有这个文件需要新建一个。
所有用户有效,配置文件:/etc/vimrc 一般不更改它。
测试效果: