augroup bufclosetrackĪutocmd WinLeave * let g:lastWinName = ENDĬommand -nargs=0 LastWindow call LastWindow() I played around with this a bit and the following seems to work for the cases I tested, including closing a window split and a tab with one window using :q.