Skip to content

Instantly share code, notes, and snippets.

@othree
Created September 8, 2009 14:34
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save othree/182971 to your computer and use it in GitHub Desktop.
[vimrc] Auto compile JS/CSS file after saving it.
function Js_css_compress ()
let cwd = expand('<afile>:p:h')
let nam = expand('<afile>:t:r')
let ext = expand('<afile>:e')
if -1 == match(nam, "[\._]src$")
let minfname = nam.".min.".ext
else
let minfname = substitute(nam, "[\._]src$", "", "g").".".ext
endif
if ext == 'less'
if executable('lessc')
cal system( 'lessc '.cwd.'/'.nam.'.'.ext.' &')
endif
else
if filewritable(cwd.'/'.minfname)
if ext == 'js' && executable('closure-compiler')
cal system( 'closure-compiler --js '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
elseif executable('yuicompressor')
cal system( 'yuicompressor '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
endif
endif
endif
endfunction
autocmd FileWritePost,BufWritePost *.js :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.css :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.less :call Js_css_compress()
@othree
Copy link
Author

othree commented Feb 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment