12

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.

Jeromy Anglim
  • 271
  • 2
  • 10

1 Answers1

16

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!
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
cjh
  • 1,509
  • 13
  • 13