Skip to content

Instantly share code, notes, and snippets.

@morganrallen
Last active December 17, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morganrallen/5623956 to your computer and use it in GitHub Desktop.
Save morganrallen/5623956 to your computer and use it in GitHub Desktop.
Auto compile LESS to CSS on write. Also will allow you to compile a parent script by putting /* lessc-parent: "main" */ on the top line
function LessToCss()
let match = matchstr(getline(1), '...lessc-parent: "\zs.\{-}\ze"')
if strlen(match) > 0
let current_file = match . ".less"
let filename = match
el
let current_file = shellescape(expand('%:p'))
let filename = shellescape(expand('%:r'))
endif
let command = "silent !lessc --line-numbers=mediaquery " . current_file . " " . filename . ".css"
execute command
endfunction
autocmd BufWritePost,FileWritePost *.less call LessToCss()
autocmd BufReadPost,FileReadPost *.less set ft=css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment