Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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 : isnt needed in vimrc).

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

:au FocusGained * :q!
share|improve this answer
    
Thanks. I gave it a basic test, and it seemed to work without any performance issues. –  Jeromy Anglim Dec 20 '12 at 4:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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