I'd like :bd and :bw to actually quit my vim session if, after the current buffer is removed, the buffer list is empty (i.e. if, before executing :bd or :bw, I only had the current buffer in the buffer list). How can I accomplish this? I'd assume it should be pretty easy, but googling hasn't really yielded anything useful, and so far I haven't managed to write an autocmd to accomplish this.
Answer
To check for a single buffer, you need to iterate over all potential buffers and check whether they are still listed (e.g. in :ls). The check is triggered whenever a buffer is deleted:
:autocmd BufDelete * if len(filter(range(1, bufnr('$')), '! empty(bufname(v:val)) && buflisted(v:val)')) == 1 | quit | endif
No comments:
Post a Comment