"1、自动保存和加载上一次vim打开的编辑信息
" 设置mksession
" 设置sessionoptions可以用在UNIX下 set sessionoptions+=slash set sessionoptions+=unix " 设置sessionoptions使用相对路径 set sessionoptions-=curdir set sessionoptions+=sesdir set sessionoptions-=blank "设置启动时自动退出时自动保存读取项目相关配置function! SaveProject()
"不保存winManger窗口 WMClose "不保存NERDTree窗口 NERDTreeClose "不保存Tlist,如果有__Tag_List__,说明打开了Tlist,保存之前那么关闭Tlist if(bufexists("__Tag_List__")!=0) TlistClose endif echo "Saving ".s:curProjectSession execute 'mksession! '.s:curProjectSession echo "Saving ".s:curProjectInfo execute 'wviminfo! '.s:curProjectInfo endfunction function! AutoSaveProject()"由于经常要临时修改1,2个文件,但是这种情况下又不想自动保存和加载编辑信息,所以设置为在项目目录下直接运行vim才会自动保存上一次的编辑信息
"默认情况下不主动保存编辑信息,只有在手工保存过一次后才认为需要自动保存编辑信息
if(argc()==0 && (filereadable(s:curProjectSession) || filereadable(s:curProjectInfo))) call SaveProject() endif endfunctionfunction! LoadProject()
let s:curWorkDir=getcwd() let s:curProjectSession=s:curWorkDir."/project.vim" let s:curProjectInfo=s:curWorkDir."/project.viminfo" if(filereadable(s:curProjectSession)) "echo "Loading ".s:curProjectSession execute 'source '.s:curProjectSession endif if(filereadable(s:curProjectInfo)) "echo "Loading ".s:curProjectInfo execute 'rviminfo '.s:curProjectInfo endif endfunction function! AutoLoadProject()"由于经常要临时修改1,2个文件,但是这种情况下又不想自动保存和加载编辑信息,所以设置为在项目目录下直接运行vim才会自动加载上一次的编辑信息
if(argc()==0) call LoadProject() endif endfunctionfunction! WipeProject()
if(delete(s:curProjectSession)==0) echo "Deleted ".s:curProjectSession endif if(delete(s:curProjectInfo)==0) echo "Deleted ".s:curProjectInfo endif endfunctionautocmd mine VimEnter * call AutoLoadProject() “进入vim自动加载保存的信息
autocmd mine VimLeave * call AutoSaveProject() “退出vim的时候自动保存信息
"2、自动上传文件到FTP上
let g:uploadIp="10.8.6.10"
let s:projectRootPath="" function! Upload() let fileName=bufname("%") if fileName=~ ":" while s:projectRootPath == "" || fileName!~s:projectRootPath let s:projectRootPath=input("请输入项目根目录:") let s:projectRootPath=escape(s:projectRootPath,'\') endwhile let fileName= substitute(fileName,s:projectRootPath, "", "") endif let fileName= substitute(fileName,"\\","/","g") let fileName="ftp://".g:uploadIp."/".fileName echo fileName execute "Nwrite ".fileName " echo substitute('D:\Program Files\Vim',".+Vim","") endfunctionlet g:isAutoUpload=0 ”默认不开启自动上传
function! AutoUpload() if g:isAutoUpload==1 call Upload() endif endfunction"3、运行正在编辑的脚本文件
function RunMe()
if &filetype == "python" !python % elseif &filetype == "perl" !perl % else !% "用默认的打开方式打开 endif endfunction"4、根据文件后缀读取配置信息
let s:myVimrcPath=$VIMRUNTIME."/myVimrc/" ”设置脚本所在的目录 function LoadMyVimrc() let s:myVimrcPathFt=s:myVimrcPath.expand("%:e")."/" let s:myVimrcFilesFt=s:myVimrcPathFt."*.vim" echo glob(s:myVimrcFilesFt) let s:myVimrcFilesFtList=split(glob(s:myVimrcFilesFt)) for s:myVimrcFileFt in s:myVimrcFilesFtList if executable(s:myVimrcFileFt) source s:myVimrcFileFt endif endfor endfunction