Asenar Asenar - 6 months ago 12
Bash Question

excuting vim command silently then echo in vim

I want to execute a shell command on

autocmd BufWrite
in my
.vimrc
, then echo (in vim) a message saying it's donem without showing the shell.

(basically
touch *.less
), then echo an information message saying "file touched !".

The first part works, but the 2nd command is executed in the shell instead of vim.

The command should be something like this:

autocmd BufWritePost *.less silent! !touch '%:p:h'/*.less | echo 'file '.expand('%:p:h').' touched !'


I think I need a way to "ends" the command and allow an other command.

I tried this without more success:

:silent !touch '%:p:h'/*.less && exit 0 | unsilent! | echo "file touched"


Any idea ?

Answer

It should work if you past by a function :

function! Cmd()
    silent! execute '! touch %:p:h/*.less'
    echo 'file '.expand('%:p:h').' touched !'
endfunction

autocmd BufWritePost *.less call Cmd()
Comments