Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""新文件标题
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java,*.py exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1,"\#!/bin/bash")
call append(line("."), "")
elseif &filetype == 'python'
call setline(1,"#!/usr/bin/env python")
call append(line("."),"# coding=utf-8")
call append(line(".")+1, "")
elseif &filetype == 'mkd'
call setline(1,"<head><meta charset=\"UTF-8\"></head>")
else
call setline(1, "#include<functional>")
endif
if &filetype == 'cpp'
call append(line("."), "#include<algorithm>")
call append(line(".")+1, "#include<iostream>")
call append(line(".")+2, "#include<fstream>")
call append(line(".")+3, "#include<sstream>")
call append(line(".")+4, "#include<iomanip>")
call append(line(".")+5, "#include<numeric>")
call append(line(".")+6, "#include<cstring>")
call append(line(".")+7, "#include<climits>")
call append(line(".")+8, "#include<cassert>")
call append(line(".")+9, "#include<cstdio>")
call append(line(".")+10, "#include<string>")
call append(line(".")+11, "#include<vector>")
call append(line(".")+12, "#include<bitset>")
call append(line(".")+13, "#include<queue>")
call append(line(".")+14, "#include<stack>")
call append(line(".")+15, "#include<cmath>")
call append(line(".")+16, "#include<ctime>")
call append(line(".")+17, "#include<list>")
call append(line(".")+18, "#include<set>")
call append(line(".")+19, "#include<map>")
call append(line(".")+20, "using namespace std;")
call append(line(".")+21, "int getnum()//读大量数据特别快")
call append(line(".")+22, "{")
call append(line(".")+23, " char ch;")
call append(line(".")+24, " while(ch=getchar(),ch==10||ch==32);")
call append(line(".")+25, " int ans=ch-48;")
call append(line(".")+26, " while((ch=getchar())!=EOF&&(ch>='0'&&ch<='9'))")
call append(line(".")+27, " {")
call append(line(".")+28, " ans*=10;")
call append(line(".")+29, " ans+=ch-'0';")
call append(line(".")+30, " }")
call append(line(".")+31, " return ans;")
call append(line(".")+32, "}")
call append(line(".")+33, "int main(int argc,char *argv[])")
call append(line(".")+34, "")
endif
if &filetype == 'c'
call append(line("."), "#include<stdlib.h>")
call append(line(".")+1, "#include<string.h>")
call append(line(".")+2, "#include<stdio.h>")
call append(line(".")+3, "#include<math.h>")
call append(line(".")+4, "int main()")
call append(line(".")+5, "")
endif
"
if &filetype == 'java'
"
call append(line("."),"public class ".expand("%"))
"
call append(line(".")+1,"")
"
endif
"新建文件后,自动定位到文件末尾
endfunc
autocmd BufNewFile * normal G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment