I am writing
a.lessFile, I want to be in execution
:wCalled automatically when a command is saved
lesscCommand to compile the file into
lesscThe format of the command is
lessc a.less a.css.
How should I set it up?
Don’t know why.
autocmd BufWritePostIt doesn’t work, then it only works
autocmd BufWriteCmdHere we go.
function! CompileLess() exec "w" exec "! lessc % > %:t:r.css" endfunction if executable("lessc") autocmd BufWriteCmd *.less call CompileLess() endif
The general code is as follows. cmd has perfected itself. system can be used to retrieve the compilation results. If there is an error, it will be output, so as to locate the error well.
function! CompileLess() let cmd = 'lessc + ' + expand('<afile>:p:h') let output = system(cmd) if v:shell_error echohl WarningMsg | echo output endif endfunction if executable('lessc') autocmd BufWritePost *.less call CompileLess() endif