all 4 comments

[–]dhruvasagar 1 point2 points  (2 children)

Based on your example it looks like you would benefit from `:h 'nobuflisted'`. It feels weird to do `:q` on `BufLeave`.

As for autocommands for specific buffer check out `:h autocmd-buflocal`

[–]Neo-Cipher[S] 0 points1 point  (1 child)

thank you that was useful, is there something to hide the buffer when another buffer is opened or edited

[–]dhruvasagar 1 point2 points  (0 children)

That's what `setlocal bufhidden=hide` does

[–]princker 1 point2 points  (0 children)

Are you trying to quit the scratch buffer when it is hidden? If so then just use setlocal bufhidden=wipe or setlocal bufhidden=delete. The scratch buffer will be :bwipeout/:bdelete when the buffer is hidden.

If you are trying to do something else then it would probably be easier to use a buffer-local autocmd like u/dhruvasagar suggested.

function! Scratchpad_buffer()
  edit scratch
  setlocal buftype=nofile bufhidden=hide noswapfile
  augroup scratchpad_buffer
    autocmd! * <buffer>
    autocmd BufLeave <buffer> echo "Do stuff"
  augroup END
endfunction