修改/etc/vimrc配置文件,在文件末尾添加如下内容即可
" 侦测文件类型
filetype on
" 载入文件类型插件
filetype plugin on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""新文件标题""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch] exec ":call SetTitleC()"
autocmd BufNewFile *.sh exec ":call SetTitleSh()"
autocmd BufNewFile *.php exec ":call SetTitlePhp()"
autocmd BufNewFile *.py exec ":call SetTitlePy()"
autocmd BufNewFile *.html,*.htm,*.phtml exec ":call SetTitleHtml()"
autocmd BufNewFile *.css exec ":call SetTitleCss()"
autocmd BufNewFile *.java exec ":call SetTitleJava()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
call setline(1, "#/*************************************************************************")
call append(line("."), "# > File Name: ".expand("%"))
call append(line(".")+1, "# > Author: liyong")
call append(line(".")+2, "# > Mail: 2550702985@qq.com")
call append(line(".")+3, "# > Created Time: ".strftime("%Y-%m-%d %H:%M"))
call append(line(".")+4, "# > Modified Time: ".strftime("%Y-%m-%d %H:%M"))
call append(line(".")+5, "# ************************************************************************/")
endfunc
func SetTitleC()
call SetTitle()
call append(line(".")+6, "#include")
call append(line(".")+7, "")
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc
func SetTitleSh()
call SetTitle()
call append(line(".")+6, "\#!/bin/bash")
call append(line(".")+7, "")
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc
func SetTitlePhp()
call SetTitle()
call append(line(".")+6, "
关注
打赏