I often use Control+L to redraw the screen in Vim.

In particular, when I come out of sleep or change monitor configurations I often find that Vim needs to be redrawn. I thought it might be simpler to just add something to my vimrc that redraws on focus.

  • Is there a command that I can add to my .vimrc file that redraws the buffer when the window/buffer gets the focus?

In particular, a good command should have no noticeable negative performance or other related side effects.

1 Answer 1


vim has an event you can bind to for this, FocusGained, combine this with the redraw! command (the ! causes the window to be cleared first)

:au FocusGained * :redraw!

The syntax here can be read as 'automatically run the command (au is short for autocmd) :redraw! when I get the event FocusGained for any file matching the pattern *'.

to make this permanent add it to your ~/.vimrc (the leading : isn't needed in vimrc).

to test events you can use a more 'obvious' command like

:au FocusGained * :q!
  • 1
    Thanks. I gave it a basic test, and it seemed to work without any performance issues. Dec 20, 2012 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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