" define function to turn current buffer into a scratch buffer
function! s:Scratch(...)
  setlocal buftype=nofile bufhidden=hide noswapfile

  if exists('a:1')
    execute 'set filetype=' . a:1
  endif
endfunction

" define commands to open scratch buffers with Scratch()
command! -nargs=? -complete=filetype Scratch enew | call s:Scratch(<q-args>)
command! -nargs=? -complete=filetype SScratch split | Scratch <args>
command! -nargs=? -complete=filetype VScratch vsplit | Scratch <args>
command! -nargs=? -complete=filetype TScratch tabnew | Scratch <args>

" define function to turn current buffer into a scratch buffer
function! s:Scratch(...)
  setlocal buftype=nofile bufhidden=delete noswapfile

  if exists('a:1')
    execute 'set filetype=' . a:1
  endif
endfunction

" define commands to open scratch buffers with Scratch()
command! -nargs=? -complete=filetype Scratch enew | call s:Scratch(<q-args>)
command! -nargs=? -complete=filetype SScratch split | Scratch <args>
command! -nargs=? -complete=filetype VScratch vsplit | Scratch <args>
command! -nargs=? -complete=filetype TScratch tabnew | Scratch <args>

Delete Scratch buffers on hide
Delete Scratch buffers on hide

The previous setting of bufhidden=hide in Scratch buffers caused tons of
[No Name] buffers to pop up the more I opened new Scratch buffers.

I rarely need to persist a Scratch buffer, so I just opted to delete
Scratch buffers after closing their windows.

igemnace/vim-config,igemnace/vim-config,igemnace/my-vim-config,igemnace/vim-config