From 7085965e05f780a0436a788e91132a142e66a2a1 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 21 Feb 2021 14:21:32 +0800 Subject: [PATCH] Refactor the auto-quit logic Also quit quickfix window if it is the only window left. --- core/autocommands.vim | 14 ++++++++++++++ core/plugins.vim | 10 +--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/autocommands.vim b/core/autocommands.vim index 00c48e2..28503d8 100644 --- a/core/autocommands.vim +++ b/core/autocommands.vim @@ -83,4 +83,18 @@ augroup cursor_color autocmd ColorScheme * highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black autocmd ColorScheme * highlight Cursor2 guifg=red guibg=red augroup END + +augroup auto_close_win + autocmd! + autocmd BufEnter * call s:quit_current_win() +augroup END + +" Quit Neovim if we have only one window, and its filetype match our pattern. +function! s:quit_current_win() abort + let quit_filetypes = ['qf', 'vista'] + let buftype = getbufvar(bufnr(), '&filetype') + if winnr('$') == 1 && index(quit_filetypes, buftype) != -1 + quit + endif +endfunction "} diff --git a/core/plugins.vim b/core/plugins.vim index 9bba13d..99c934e 100644 --- a/core/plugins.vim +++ b/core/plugins.vim @@ -588,22 +588,14 @@ let g:vista_echo_cursor = 0 " Stay in current window when vista window is opened let g:vista_stay_on_open = 0 -augroup matchup_conf +augroup vista_conf autocmd! " Double mouse click to go to a tag autocmd FileType vista* nnoremap \ <2-LeftMouse> :call vista#cursor#FoldOrJump() - " Quit Neovim if vista window is the only window - autocmd BufEnter * call s:close_vista_win() augroup END nnoremap t :Vista!! - -function! s:close_vista_win() abort - if winnr('$') == 1 && getbufvar(bufnr(), '&filetype') ==# 'vista' - quit - endif -endfunction "}} "{{ File editting