vimrc - How to configure vim to automatically execute a certain command line command when executing the :w save command?
我想大声告诉你
我想大声告诉你 2017-05-16 16:36:31
0
3
958

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
我想大声告诉你
我想大声告诉你

reply all(3)
小葫芦

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
Ty80

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template