Skip to content

Instantly share code, notes, and snippets.

@zrong
Created December 19, 2011 01:51
Show Gist options
  • Save zrong/1495093 to your computer and use it in GitHub Desktop.
Save zrong/1495093 to your computer and use it in GitHub Desktop.
Vim+Ant编译环境配置
command! -nargs=* Make call Ant(<f-args>)
" 映射编译快捷键
cmap <F11> Make fdb 0
map <F11> :Make fdb 0<CR>
map <S-F11> :Make 0 0<CR>
cmap <F12> Make ftp 0
map <F12> :Make ftp 0<CR>
function! GetMainFile(...)
if exists('a:1')
return 'src/'.a:1.'.as'
endif
" 从ant属性文件中获取此项目的主文件名
let build = 'build.properties'
if !filereadable(build)
call Echo('找不到文件:'.build)
return 0
endif
let prop = readfile(build)
let pat = '^main\s\?=\s\?\(\i\+\)$'
for aline in prop
if aline =~ pat
let l:main = substitute(aline, pat, '\1', '')
break
endif
endfor
if !exists('l:main')
call Echo('找不到主文件名的定义!')
return 0
endif
return 'src/'.l:main.'.as'
endfunction
" 参数1 要执行的ant的任务名,逗号分隔。可用值为init,ftp,fdb
" 参数2 文件名后缀
" 参数3 编译的主文件名
" 参数4 是否编译Debug版
function! Ant(...)
let param = ''
let local = 'false'
let main = GetMainFile()
if exists('a:1') && a:1 != '0'
let targets = split(a:1, ',')
for targetName in targets
let param .= ' -D'.targetName.'=true'
endfor
endif
if exists('a:2')
" 允许使用后缀,就加入后缀
if a:2 != '0'
let param .= " -Dpost=".a:2
endif
" 没有设置后缀参数,默认加_local后缀
else
let param .= ' -Dpost=_local'
let local = 'true'
endif
if exists('a:3')
if a:3 != '0'
let main = GetMainFile(a:3)
let param .= ' -Dmain='.a:3
endif
endif
if exists('a:4') && a:4 == '0'
let param .= ' -Ddebug=false'
endif
" 在主文件中写入编译时间
call WriteSource(main, local)
execute 'echo "make'.param.'"'
execute 'make '.param
endfunction
function! WriteSource(mainFile, isLocal)
if !filereadable(a:mainFile)
return
endif
" 改变KTScreen中的值
execute 'split '.a:mainFile
" 获得本地调试定义的代码行
let localLine = search("Global.isDebug = ")
" 获取编译日期的代码行
let makeTimeLine = search('var __makeTimeMI')
let localValue = "\t\tGlobal.isDebug = $IS_LOCAL;"
let makeTimeValue = "\t\tvar __makeTimeMI:ContextMenuItem = new ContextMenuItem('$MAKE_TIME');"
" 更新编译时间
call setline(makeTimeLine, substitute(makeTimeValue, "$MAKE_TIME", strftime('%c', localtime()), ''))
" 根据参数2更新是否编译成本地调试用程序
call setline(localLine, substitute(localValue, "$IS_LOCAL", a:isLocal, ''))
execute 'update'
execute 'close'
endfunction
function! CreateProject(...)
let l:SDK = $FLEX_HOME
let l:SRC_DUDU = $DUDU_AS3
let l:TEMPLATE= $FLEX_HOME.'/build/'
if !exists('a:1')
let a:1 = getcwd()
endif
if !isdirectory(a:1)
call mkdir(a:1)
endif
echo a:1
execute 'lcd '.a:1
call mkdir('src')
call mkdir('bin')
execute 'split '.l:TEMPLATE.'build.properties'
execute '%s+\${CP_MAIN}+'.a:1."+"
execute '%s+\${CP_DUDU}+'.l:SRC_DUDU."+"
execute '%s+\${CP_SDK}+'.l:SDK."+"
execute 'save build.properties'
close
execute 'split '.l:TEMPLATE.'build.xml'
execute '%s+\${CP_MAIN}+'.a:1.'+'
execute 'save build.xml'
close
execute 'split '.l:TEMPLATE.'Main.as'
execute '%s+\${CP_MAIN}+'.a:1.'+'
execute 'save src/'.a:1.'.as'
close
endfunction
function! CreateClass(className, ...)
let l:TEMPLATE= $FLEX_HOME.'/build/'
let l:path = 'src/'
execute 'split '.l:TEMPLATE.'Class.as'
execute '%s+\${CC_MAIN}+'.a:className.'+'
if exists('a:1') && len(a:1)>0
execute '%s+\${CC_PACKAGE}+ '.a:1.'+'
let l:package = split(a:1, '\.')
" 建立不存在的目录
for l:childPackage in l:package
let l:path .= l:childPackage . '/'
echo l:path
if isdirectory(l:path)
continue
endif
call mkdir(l:path)
endfor
else
execute '%s+\${CC_PACKAGE}++'
endif
if exists('a:2')
execute '%s+\${CC_EXTENDS}+ extends '.a:2.'+'
else
execute '%s+\${CC_EXTENDS}++'
endif
execute 'save '.l:path.a:className.'.as'
endfunction
"zrong加入的内容
colorscheme evening "设置配色方案
set guioptions=egmrLt "取消菜单栏的显示
set guifont=Yahei_Consolas_Hybrid:h11 "设置界面字体
set listchars=tab:>-,trail:-,eol:$ "设置显示list的时候,tab键和空格键的效果
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese,latin1
set fileformats=dos,unix,mac
set nobackup "取消备份
set hlsearch "设置搜索结果高亮
set incsearch "设置搜索的同时高亮
set showmatch "自动括号匹配
set number "显示行号
set tabstop=4 "设置制表符的显示长度为4个空格
set shiftwidth=4 "设置缩进用的制表符长度,这个值应该与tabstop相同
set diffopt=filler,vertical
"set splitright "打开的窗口默认在右边
"set splitbelow "打开的窗口默认在上面
"set autochdir "自动设置当前目录为正在编辑的文件目录
"set scrolloff=5 "设置到第几行的时候开始滚动
set autoindent "自动缩进
set smartindent
set cindent
set sessionoptions+=unix,slash "让会话文件在unit上也可以使用
set formatoptions+=mMor "自动排版功能影响多字节
" 设置编译器
set makeprg=ant
" 设置mxmlc编译的错误格式,由于mxmlc编译信息采用cp936编码,所以要转换一次
let &errorformat=iconv("%E\ \ \ \ [mxmlc]%f(%l):\ 列:\ %c\ %m,%E\ \ \ \ [mxmlc]%f:\ \%m", 'utf8', &enc)
set path+=e:\\Works\\zrong.as3.git\\src\\**
imap <A-/> <C-P>
"加入语法补全(貌似没用?)
if has("autocmd") && exists("+omnifunc")
autocmd! Filetype *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
endif
autocmd! BufNewFile,BufRead *.{md,mkd,mkdn,mark*} set filetype=markdown "加入MarkDown语法
autocmd! BufRead,BufNewFile *.as set filetype=actionscript "加入AS文件语法高亮支持
autocmd! BufRead,BufNewFile *.asc set filetype=asc "加入AS文件语法高亮支持
autocmd! BufRead,BufNewFile *.css setfiletype css "加入CSS文件语法高亮支持
autocmd! BufRead,BufNewFile *.json setfiletype json "加入json文件语法高亮支持
command! -narg=1 Findinfiles vimgrep /<args>/ src/**/*.as
" 获取目录下的所有文件的列表
function! GetFileList(...)
if exists('a:1')
let path = a:1
else
let path = glob("%:h")
endif
if exists('a:2')
let ext = a:2
else
let ext = "as"
endif
let trueList = []
" 获取子目录中的文件列表
let fileList = split(glob(path."/**/*.".ext), "\<NL>")
for afile in fileList
if isdirectory(afile)
" 排除目录
continue
end
call add(trueList, afile)
endfor
return trueList
endfunction
" 输出buffer列表到当前缓冲区
function! EchoBaddList(...)
let baddList = call("GetFileList", a:000)
for afile in baddList
execute 'normal obadd '.afile
endfor
endfunction
" 将path中的文件直接加入buffer列表
function! BaddList(...)
let baddList = call("GetFileList", a:000)
for afile in baddList
execute 'badd '.afile
endfor
endfunction
source $VIM/ant.vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment