#设置shell python文件头
#任意位置编辑.vim即可
#前三行为设置项,忽略大小写,缩进,自动对齐
cat > .vimrc << EOF
set ignorecase
set cursorline
set autoindent
# 设置sh文件头信息
autocmd BufNewFile *.sh exec ":call SetShTitle()"
func SetShTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/sh")
call setline(2,"###############################")
call setline(3,"# Author: jerry.jin")
call setline(4,"# Create Date: ".strftime("%Y/%m/%d"))
call setline(5,"# FileName: ".expand("%"))
call setline(6,"# Desc: ")
call setline(7,"#")
call setline(8,"###############################")
call setline(9,"")
endif
endfunc
# 设置py文件头信息
autocmd BufNewFile *.py exec ":call SetPyTitle()"
func SetPyTitle()
if expand("%:e") == 'py'
call setline(1,"#!/bin/env python")
call setline(2,"###############################")
call setline(3,"# Version: 0.1")
call setline(4,"# Author: jerry.jin")
call setline(5,"# Create Date: ".strftime("%Y/%m/%d"))
call setline(6,"# FileName: ".expand("%"))
call setline(7,"# Desc: ")
call setline(8,"###############################")
call setline(9,"")
endif
endfunc
autocmd BufNewFile * normal G
EOF
示例:
#!/bin/env python
###############################
# Version: 0.1
# Author: jerry.jin
# Date: 2021/08/25
# FileName: xxxxx.py
# Desc:
###############################
#!/bin/sh
###############################
# Author: jerry.jin
# Date: 2021/08/25
# FileName: xxxxx.sh
# Desc:
#
###############################
借鉴出处
#https://www.cnblogs.com/lpeng94/p/12662755.html