Reputation: 10183
If I open vim to edit multiple files using an invocation such as vim file1 file2 file3
and then proceed to edit each file and close the buffer using :bd
I am left with an empty buffer once I have closed all the file buffers.
How would I change the behaviour so that when I close the last file buffer (with :bd
), instead of dropping me into an empty buffer, Vim quits instead. Similar to nano
s behaviour when editing multiple files and using Ctrl+X
to close a buffer.
Upvotes: 2
Views: 196
Reputation: 924
This should achieve what you're asking for. It iterates over all potential buffers and checks whether there are any buffers still listed or empty. 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
Upvotes: 5
Reputation: 84531
How would I change the behaviour so that when I close the last file buffer,
instead of dropping me into an empty buffer, Vim quits instead.
After your last edit, end with :wqa
If that isn't the behavior you are looking for perhaps you are looking for bbye
Upvotes: 0