I would like to change the command : x in Vim to close the buffer, if it is not the last buffer, then it should behave as it is now (i.e. close vim).
I read some things here , but it does not go completely. I also use NERDTree and would like this to be ignored when considering if this is the last buffer.
I have a partially working solution based on the link I talked about, but this makes it impossible to exit vim with the vim command (because the exit command was reassigned).
I have
cnoreabbrev <expr> x getcmdtype() == ":" && getcmdline() == 'x' ? 'w<bar>bd' : 'x' cnoreabbrev <expr> wq getcmdtype() == ":" && getcmdline() == 'wq' ? 'w<bar>bd' : 'wq' cnoreabbrev <expr> q getcmdtype() == ":" && getcmdline() == 'q' ? 'bd' : 'q'
So : x (or : w q ) saves and closes the current buffer and: q just closes it.
I would like to add ... If this buffer is also the last buffer (ignoring NERDTree), it will also exit vim.
Is it possible?
source share