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
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
I don’t know about vim, but you can use tools like gulp to monitor file updates
Your idea of solving the problem is quite strange.