The WinResized event is useful to know the change of window height and width. It works fine upon :resize and CTRL W<. But when a user drags and drops the status line or vertical split bar to resize window, the event happens repeatedly.

Is there any way or tips to catch the last event and ignore other ones?


1 Answer 1


When an event occurs, you cannot know whether it was the last event in a series of events. Simply because you cannot see into the future. The (language agnostic) solution is to wait for a small amount of time for another event.

See :help timer for the functions needed to create a callback for whatever it is you want to do.

The code could look roughly like this:

let g:last_timer = 0
function On_last_event(callback)
    call timer_stop(g:last_timer)
    let g:last_timer = timer_start(200, a:callback)

autocmd WinResized * call On_last_event('MyGreatFunction')

This will call MyGreatFunction(<timer id>) 200 ms after a WinResized event.

On a side note, it might be easier to do something on every event and accept that some superfluous operations are performed.

  • Thanks. Your idea is nice. I will call timer_start() with something like function(a:callback, [v:event.windows]) so the callback can handle the resized windows.
    – Rick Howe
    Jan 16 at 5:27

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.