Home

Awesome

vim-smartq

Master key for quitting vim buffers.

Exit/Delete buffer with respect to window splits and tabs, and other types of buffer.

Features

Preserve splits across tabs

Preserve Splits

Zen-mode Integration

Zen-mode Integration

Goyo Integration

Goyo Integration

Close all diff buffers

Diff

Additional features

Installation

Using vim-plug

Plug 'marklcrns/vim-smartq'

Using dein

call dein#add('marklcrns/vim-smartq')

other package managers may be used as well.

Usage

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.

Mappings

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

Customization

" 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

SmartQ Quit Prioritization

Ordered list of SmartQ quit conditions. Once SmartQ command is executed, it will find and ONLY EXECUTE ONE condition from the list below.

  1. Delete (bd) all diff buffers. Check: :set diff?
  2. Delete (bd) Zen-mode buffer
  3. Delete (bd) Goyo buffer
  4. Quit (q)
  1. On final buffer i. Close (close!) all modifiable windows OR Quit all (qa) if empty buffer
  2. On final buffer with nomodifiable window(s) i. Quit all (qa) if empty buffer
  3. Wipe (bw)
  1. Catch all: Delete (bd) buffer. Check: :buffers

See diff, modifiable, filetype, buftype, buffers

Credits