Ruby学习笔记二帮助生成Vim添加代码头的代码
脚本语言真是太强了。
我的目的是把我的默认代码头功能加到Vim里面。
/****************************************************************************** *COPYRIGHTNOTICE *Copyright(c)2014Allrightsreserved *----StayHungryStayFoolish---- * *@author:Shen *@name: *@file:G:\MySourceCode\DefaultCode.cpp *@date:2014/06/1402:44 *@algorithm: ******************************************************************************/ //#pragmaGCCoptimize("O2") //#pragmacomment(linker,"/STACK:1024000000,1024000000") #include<bits/stdc++.h> #include<cmath> #include<cstdio> #include<string> #include<cstring> #include<iomanip> #include<iostream> #include<algorithm> usingnamespacestd; template<classT>inlineboolupdateMin(T&a,Tb){returna>b?a=b,1:0;} template<classT>inlineboolupdateMax(T&a,Tb){returna<b?a=b,1:0;} /*//STL #include<map> #include<vector> #include<list> #include<stack> #include<deque> #include<queue> */ /*//ComputationalGeometry #include<complex> #definexreal() #defineyimag() typedefcomplex<double>point; */ typedeflonglongint64; voidsolve() { } intmain() { return0; }
用Ruby10行就搞定了字符串的处理。简直爽爆了。
defload(path) File.foreach(path)do|line| line["\n"]="" str="letl=l+1|callsetline(l,\'#{line}\')" File.open("s.txt","a")do|f| f<<"#{str}\n" end end end load("DefaultCode.cpp")
最后人工把头尾一加,搞定了。
"F4添加文件头 map<F4>:callTitleDet()<cr> functionAddTitle() letl=0 letl=l+1|callsetline(l,'/******************************************************************************') letl=l+1|callsetline(l,'*COPYRIGHTNOTICE') letl=l+1|callsetline(l,'*Copyright(c)2014Allrightsreserved') letl=l+1|callsetline(l,'*----StayHungryStayFoolish----') letl=l+1|callsetline(l,'*') letl=l+1|callsetline(l,'*@author:Shen') letl=l+1|callsetline(l,'*@name:') letl=l+1|callsetline(l,'*@file:'.expand("%:p:h")."\\".expand("%:t")) letl=l+1|callsetline(l,'*@date:'.strftime("%Y/%m/%d%H:%M")) letl=l+1|callsetline(l,'*@algorithm:') letl=l+1|callsetline(l,'******************************************************************************/') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'//#pragmaGCCoptimize("O2")') letl=l+1|callsetline(l,'//#pragmacomment(linker,"/STACK:1024000000,1024000000")') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'#include<bits/stdc++.h>') letl=l+1|callsetline(l,'#include<cmath>') letl=l+1|callsetline(l,'#include<cstdio>') letl=l+1|callsetline(l,'#include<string>') letl=l+1|callsetline(l,'#include<cstring>') letl=l+1|callsetline(l,'#include<iomanip>') letl=l+1|callsetline(l,'#include<iostream>') letl=l+1|callsetline(l,'#include<algorithm>') letl=l+1|callsetline(l,'usingnamespacestd;') letl=l+1|callsetline(l,'template<classT>inlineboolupdateMin(T&a,Tb){returna>b?a=b,1:0;}') letl=l+1|callsetline(l,'template<classT>inlineboolupdateMax(T&a,Tb){returna<b?a=b,1:0;}') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'/*//STL') letl=l+1|callsetline(l,'#include<map>') letl=l+1|callsetline(l,'#include<vector>') letl=l+1|callsetline(l,'#include<list>') letl=l+1|callsetline(l,'#include<stack>') letl=l+1|callsetline(l,'#include<deque>') letl=l+1|callsetline(l,'#include<queue>') letl=l+1|callsetline(l,'*/') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'/*//ComputationalGeometry') letl=l+1|callsetline(l,'#include<complex>') letl=l+1|callsetline(l,'#definexreal()') letl=l+1|callsetline(l,'#defineyimag()') letl=l+1|callsetline(l,'typedefcomplex<double>point;') letl=l+1|callsetline(l,'*/') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'typedeflonglongint64;') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'voidsolve()') letl=l+1|callsetline(l,'{') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'}') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'intmain()') letl=l+1|callsetline(l,'{') letl=l+1|callsetline(l,'') letl=l+1|callsetline(l,'return0;') letl=l+1|callsetline(l,'}') endfunction "更新最近修改时间和文件名 functionUpdateTitle() callsetline(8,'*@file:'.expand("%:p:h")."\\".expand("%:t")) callsetline(9,'*@date:'.strftime("%Y/%m/%d%H:%M")) endfunction "判断前10行代码里面,是否有COPYRIGHTNOTICE这个单词, "如果没有的话,代表没有添加过作者信息,需要新添加; "如果有的话,那么只需要更新即可 functionTitleDet() letn=2 "默认为添加 letline=getline(n) letstr='^*COPYRIGHTNOTICE$' ifline=~str callUpdateTitle() return endif callAddTitle() endfunction