Master key for quitting vim buffers.
Exit/Delete buffer with respect to window splits and tabs, and other types of buffer.
Preserve splits across tabs
Zen-mode Integration
Goyo Integration
Close all diff buffers
Additional features
- Close all splits in current tab when one empty modifiable buffer remaining with multiple splits.
- Auto wipe empty buffers when deleting/wiping a buffer
Using vim-plug
Plug 'marklcrns/vim-smartq'
Using dein
call dein#add('marklcrns/vim-smartq')
other package managers may be used as well.
Plug and play. Automatically remap macro record q
to Q
, then map q
to
<Plug>(smartq_this)
and <C-q>
to <Plug>(smartq_this_force)
:SmartQ {buffer} " Smart quit (buffer name/number, optional)
:SmartQ! {buffer} " Same as above but forced
:SmartQSave {buffer} " Smart save before quit (buffer name/number, optional)
:SmartQWipeEmpty " Wipe all empty (untitled) buffers
:SmartQWipeEmpty! " Same as above but forced
:SmartQCloseSplits " Close all splits excluding non-modifiable buffers
Tip: SmartQ(!) accepts both buffer name and buffer number (see :buffers). Also supports tab completion.
nmap <Plug>(smartq_this) " :SmartQ
nmap <Plug>(smartq_this_save) " :SmartQSave
nmap <Plug>(smartq_this_force) " :SmartQ!
nmap <Plug>(smartq_wipe_empty) " :SmartQWipeEmpty
nmap <Plug>(smartq_wipe_empty_force) " :SmartQWipeEmpty!
nmap <Plug>(smartq_close_splits) " :SmartQCloseSplits
" Default Settings
" -----
" Default mappings:
" Remaps normal mode macro record q to Q
" nnoremap Q q
" nmap q <Plug>(smartq_this)
" nmap <C-q> <Plug>(smartq_this_force)
let g:smartq_default_mappings = 1
" Excluded buffers to disable SmartQ and to preserve windows when closing splits
" on excluded buffers. Non-modifiable buffers are preserved by default.
let g:smartq_exclude_filetypes = [
\ 'fugitive'
\ ]
let g:smartq_exclude_buftypes= [
\ ''
\ ]
" Quit buffers using :q command. Non-modifiable and readonly file uses :q
let g:smartq_q_filetypes = [
\ 'diff', 'git', 'gina-status', 'gina-commit', 'snippets',
\ 'floaterm'
\ ]
let g:smartq_q_buftypes = [
\ 'quickfix', 'nofile'
\ ]
" Wipe buffers using :bw command. Wiped buffers are removed from jumplist
" Default :bd
let g:smartq_bw_filetypes = [
\ ''
\ ]
let g:smartq_bw_buftypes = [
\ ''
\ ]
" Automatically wipe empty (with no changes) buffer(s)
let g:smartq_auto_wipe_emtpy = 1
" Best attemp to prevent exiting editor when left with an empty modifiable buffer
let g:smartq_no_exit = 0
" Automatically close splits when left with 1 modifiable buffer
let g:smartq_auto_close_splits = 0
" --- PLUGIN INTEGRATIONS
" When a plugin is disabled, use built-in fallbacks
" Enable Goyo
let g:smartq_goyo_integration = 1
" Enable Zen-mode
let g:smartq_zenmode_integration = 1
Ordered list of SmartQ quit conditions. Once SmartQ
command is executed, it
will find and ONLY EXECUTE ONE condition from the list below.
- Delete (
bd
) alldiff
buffers. Check::set diff?
- Delete (
bd
) Zen-mode buffer - Delete (
bd
) Goyo buffer - Quit (
q
)
smartq_q_filetypes
orsmartq_q_buftypes
terminal
buffernomodifiable
orreadonly
window- Exceptions:
smartq_exclude_filetypes
,smartq_exclude_buftypes
, emptyfiletype
andbuftype
- On final buffer
i. Close (
close!
) allmodifiable
windows OR Quit all (qa
) if empty buffer - On final buffer with
nomodifiable
window(s) i. Quit all (qa
) if empty buffer - Wipe (
bw
)
smartq_bw_filetypes
orsmartq_bw_buftypes
- Exceptions:
smartq_exclude_filetypes
,smartq_exclude_buftypes
, emptyfiletype
andbuftype
- Catch all: Delete (
bd
) buffer. Check::buffers
See diff
, modifiable
, filetype
, buftype
, buffers