Friday, November 2, 2012

Re: xa and abandon unnamed buffers

On 03/11/12 00:16, Chris Lott wrote:
> Is there a command that will write and exit all buffers *and* abandon
> unnamed buffers? xa almost gets there, but it fails if there are
> unnamed buffers.
>
> c
> --
> Chris Lott <chris@chrislott.org>
>
AFAIK, there isn't. At least a cursory reading of ":help writing" and
":help write-quit" doesn't reveal anything obvious.

You might try
:confirm xa
which will prompt you to save or abandon any modified buffer, but I
suppose this is not what you want.

Or you could write a function to do it, maybe something like (untested)

function Xall()
for t in range(1, tabpagenr('$')
for b in tabpagebuflist(t)
if bufloaded(b)
\ && bufname(b) == ""
\ && getbufvar(b, '&mod')
exe 'bw!' b
endif
endfor
endfor
xall
endfunc
command Xall call Xall()

If I haven't goofed, the first part wipes out all modified unnamed
buffers which are loaded (in a window or hidden), then the last
instruction (xall) writes all modified named buffers and quits Vim.

You won't get a warning if you've entered important stuff in an unnamed
buffer: it will be sent to never-never land, from where you won't be
able to get it back.

Please test this function thoroughly before deciding that it suits your
needs: it is a dangerous function if there are any bugs in it, and I
have NOT tested it myself.


Best regards,
Tony.
--
TALL KNIGHT: Firstly. You must get us another shrubbery!
OTHER KNIGHTS: More shrubberies! More shrubberies for the ex-Knights of Ni!
ARTHUR: Not another shrubbery -
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment