Say I write an autocommand for a particular file to do something when I save it, such as

autocmd BufWritePost .Xresources silent! execute 'xrdb ~/.Xresources'

I'm doing it with silent! execute, because if I only use

autocmd BufWritePost .Xresources !xrdb ~/.Xresources

vim would prompt for an enter. But I still want to see that the reload happened, which I thought could be handled with echo, such as

autocmd BufWritePost .Xresources silent! execute 'xrdb ~/.Xresources' | echo 'Xresources reloaded'

But again this has the problem of prompting to Press ENTER or type command to continue. Now there is echon which does not do prompt for ENTER, but it also does not display the message, as saving the file with :w causes "~/.Xresources" 487L, 18435C written to be written to the status line instead.

So the quation is, is there some way to run the autocommand such that it saves the file, runs the shell command, and echoes a confirmation message in the status line, without prompting the user to press ENTER, or interrupt in any other way?

1 Answer 1


I'm not sure if the exact behavior you want is achievable. If it is it'll probably involve use of the :redraw command (or Ctrl-L in Normal mode). I haven't found the magic combo but can propose a couple "workarounds".

If you don't mind having the message displayed for a limited amount of time before it disappears you could try something like

<snip> silent! execute 'xrdb ~/.Xresources' | echo 'Xresources reloaded' | sleep 2 | redraw

Or, if you don't always need to see the confirmation and just want a way to check it explicitly now and then you could use echom and look for the message manually with :mess (or :1mess if looking for it immediately after the autocommand runs).

<yadda yadda> silent! execute 'xrdb ~/.Xresources' | echom 'Xresources reloaded' | redraw

Still, I'll see if I can find the ideal solution.

Edit: Actually...just swapping the echo and redraw positions might be the ticket!

<yadda yadda> execute 'xrdb ~/.Xresources' | redraw | echo 'Xresources reloaded'

Bonus: you might not need silent either. I've left it off but if your screen is getting jumpy or something then you can include it. Depends, at least in part, on how much output xrdb has.

I don't have xrdb and what not so I was faking it with other shell commands so you'll need to verify.

(BTW, are you missing a bang ! before xrdb? Thought it was an external command..)

  • Thanks! I'm not missing the ! since silent! execute already does that, but anyway, like you mentioned, leaving out silent! does not work as both things get shown, but autocmd BufWritePost .Xresources silent! execute 'xrdb ~/.Xresources' | redraw | echo 'Xresources reloaded' works perfectly :) Commented Nov 4, 2019 at 19:36
  • 1
    Hmm. silent! execute has no magic that allows you to leave off the ! before the external command. Are you sure the silent isn't obscuring relevant error messages? :) Anyways, that wasn't the question you asked. Glad one of my solutions works well for you. Cheers!
    – B Layer
    Commented Nov 4, 2019 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.