""定义函数SetTitle,自动插入文件头 autocmd BufNewFile *.py,*.cpp,*.sh,*.java exec ":call SetTitle()" func SetTitle() "如果文件类型为.sh文件 if &filetype == 'sh' call setline(1,"#!/bin/bash") call append(line("."), "# Author: fangtest") call append(line(".")+1, "# Created Time" . strftime("%c")) call append(line(".")+2, "") elseif &filetype == 'cpp' call setline(1,"// File Name: ".expand("%")) call append(line("."), "// Author: fangtest") call append(line(".")+1, "// Created Time: ".strftime("%c")) call append(line(".")+2, "") call append(line(".")+3, "#include<iostream>") call append(line(".")+4, "#include<string>") call append(line(".")+5, "#include<algorithm>") call append(line(".")+6, "#include<cstdlib>") call append(line(".")+7, "using namespace std;") call append(line(".")+8, "int main(){") call append(line(".")+9, "") call append(line(".")+10, " return 0") call append(line(".")+11,"}") elseif &filetype == 'python' call setline(1,"#!/usr/bin/env python") call append(line("."), "# Author: fangtest") call append(line(".")+1, "# Created Time: ".strftime("%c")) call append(line(".")+2, "") else call setline(1,"/*") call append(line("."), "* Author: fangtest") call append(line(".")+1, "* Created Time: ".strftime("%c")) call append(line(".")+2, "*/") call append(line(".")+3, "") endif "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc