I am writing a a.less
file. I want to automatically call the lessc
command to compile the file into when executing the
:w save command. a.css
file. The format of the lessc
command is lessc a.less a.css
.
How to set it up?
I don’t know why autocmd BufWritePost
doesn’t work, so I have to use autocmd BufWriteCmd
.
function! CompileLess()
exec "w"
exec "!lessc % > %:t:r.css"
endfunction
if executable("lessc")
autocmd BufWriteCmd *.less call CompileLess()
endif
高洛峰2017-05-16 16:38:31
The code is roughly as follows. You can improve it yourself in cmd. You can use system to get out the compilation result. If there is an error, it will be output, so that you can easily locate the error
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
PHP中文网2017-05-16 16:38:31
I don’t know about vim, but you can use tools like gulp to monitor file updates