Vim å½æ°, å°±æ¯è°ç¨ YUICompressor å缩 js æ css
//
æ ä¸é¢è¿ä¸ªå½æ°æ¾å° _vimrc(.vimrc ) ä¸, ä¿®æ¹ yuicompressor_program 为 jar æ件æå¨ä½ç½®;
å¦æä¸éè¦æå°è¯¦ç»ä¿¡æ¯, å¯ä»¥å»æ --verbose é项
//
使ç¨:
æå¼è¦å缩çæ件, æ§è¡
:call YUICompressor()
Â
//
ä¹å¯ä»¥å®ä¹èªå·±ç  map, 使ç¨å¿«æ·é®æ¥è°ç¨å½æ°. æè autocommand ç»å® vim åå ¥äºä»¶
Â
function! YUICompressor()
let yuicompressor_program = 'java -jar D:/tools/ourtools/yui-compressor/yuicompressor.jar --verbose'
"
let yui_option_charset = '--charset ' . &fileencoding
"
let current_file = expand('%:p')
if match(current_file, "/.js$") != -1
let yui_option_type = '--type js'
elseif match(current_file, "/.css$") != -1
let yui_option_type = '--type css'
else
echoerr 'Error: File "' . current_file . '" is not js or css!'
return
endif
"
let yui_option_outputfile = substitute(current_file, '/./(js/|css/)$', '-min/./1', "")
if yui_option_outputfile == current_file
echoerr 'Error: Cannot substitute filename to "-min" file!'
return
endif
"
let yui_option_outputfile = '-o ' . shellescape(yui_option_outputfile)
let current_file = shellescape(current_file)
"
"
let yui_options = yui_option_charset . ' ' . yui_option_type . ' ' . yui_option_outputfile . ' ' . current_file
let cmd = yuicompressor_program . ' ' . yui_options
"
"" echo cmd
"" return
"
let cmd_output = system(cmd)
"
echo cmd_output
endfunction