When using vim I like to keep my command line (the line where messages, warnings and errors are printed) empty, so after saving a file I usually issue a <C-l> to redraw the screen and clear it.

Is there a way to automate this process, so that after n seconds of something being printed in the command line, an automatic <C-l> is executed?

  • You can clear the console after saving a file using the BufWritePost event: :autocmd BufWritePost <buffer> ...
    – user382051
    Mar 25, 2020 at 8:53
  • Can I put a timer on that action, so for ex clear the console 5 seconds after saving?
    – noibe
    Mar 25, 2020 at 10:31
  • 1
    I believe this is not an easy task, have a look at this.
    – user382051
    Mar 25, 2020 at 10:34

2 Answers 2


The following autocommands may do what you want

" Clear cmd line message
function! s:empty_message(timer)
  if mode() ==# 'n'
    echon ''

augroup cmd_msg_cls
    autocmd CmdlineLeave :  call timer_start(5000, funcref('s:empty_message'))
augroup END

It will clear the commandline output 5 seconds after CmdlineLeave event is fired. It sort of works as you want. You may tweak the time as you wish.

  • so by just running echon '', the command-line screen will be cleared?
    – alexzander
    Aug 25, 2021 at 9:56
  • Yes, because you printed an empty message in the statusline.
    – jdhao
    Aug 25, 2021 at 14:53
  • i saw it, it works. but not always, sometimes doesnt clear the cmd
    – alexzander
    Aug 25, 2021 at 16:26
  • @alexzander If vim is busy doing something, the time to to the callback function may not be exactly 5 seconds.
    – jdhao
    Aug 26, 2021 at 11:20
  • im not using your autogroup. im clearing the cmd when a custom defined function is called. that function is called when i press control+S to save the file.
    – alexzander
    Aug 26, 2021 at 14:05

Adding to @jdhao answer, you can use the CursorHold event instead which uses the value of updatetime as a timeout and will trigger whenever no key is pressed.

For example:

    autocmd CursorHold * echon ''

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .