如何在vim创建脚本内添加固定的抬头信息?

注意:只在vim创建.sh后缀的文件中起作用,其他文件类型无效,如txt

配置文件 vim .vimrc

vim .vimrc

添加以下内容 

set ignorecase                                                                                                                                                        
set cursorline
set autoindent
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:        Zhouxu")
     call setline(5,"#QQ:          984402154")
     call setline(6,"#Date:         ".strftime("%Y-%m-%d"))
     call setline(7,"#FileName:       ".expand("%"))
     call setline(8,"#Copyright (C):    ".strftime("%Y")." All rights reserved")
     call setline(9,"#********************************************************************")
     call setline(10,"")
     endif
endfunc
autocmd BufNewFile * normal G

重新创建shell脚本,注意是.sh后缀文件,查看固定抬头信息

vim 12.sh

 完成


版权声明:本文为We_Are_The_hampions原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。