diff --git a/plugin/autoswap.vim b/plugin/autoswap.vim index 9542f69..6ba1789 100644 --- a/plugin/autoswap.vim +++ b/plugin/autoswap.vim @@ -57,7 +57,7 @@ function! AS_HandleSwapfile (filename, swapname) if (strlen(active_window) > 0) call AS_DelayedMsg('Switched to existing session in another window') call AS_SwitchToActiveWindow(active_window) - let v:swapchoice = 'q' + call Exit() " Otherwise, if swapfile is older than file itself, just get rid of it... elseif getftime(v:swapname) < getftime(a:filename) @@ -73,6 +73,21 @@ function! AS_HandleSwapfile (filename, swapname) endfunction +function! Exit() + if has("nvim") && exists("*GuiClose") + let l:num_buffers = len(getbufinfo({'buflisted':1})) + let l:num_windows = winnr('$') + if l:num_buffers == 1 && l:num_windows == 1 + let v:swapchoice = 'o' + autocmd BufEnter * call GuiClose() | q + else + let v:swapchoice = 'q' + endif + else + let v:swapchoice = 'q' + endif +endfunction + " Print a message after the autocommand completes " (so you can see it, but don't have to hit to continue)... "