sent 15:37:36 02 August 2011, Tuesday
by Axel Bender:
> Thanks for all your input! Used it to create a function that quits vi when
> the last buffer is closed (didn't find one that worked out of the box with
> my settings):
I would have constructed a solution using bufnr('$')+bufexists()+bufname('%'):
function QuitIfLast(wipe)
if a:wipe
bwipeout!
else
bdelete
endif
if empty(filter(range(1, bufnr('$')), 'bufexists(v:val) && '.
\ '!empty(bufname(v:val))'))
quit
endif
endfunction
Avoid :redir if possible.
Original message:
> Thanks for all your input! Used it to create a function that quits vi when
> the last buffer is closed (didn't find one that worked out of the box with
> my settings):
>
> function! QuitIfLast(wipe)
> " Delete/wipe-out the current buffer
> if a:wipe == 1
> bwipeout!
> else
> bdelete
> endif
>
> " Check to see if there are more buffers around
> redir => l:ls
> silent ls
> redir END
>
> let l:files = split(l:ls, "\n")
> if len(l:files) == 1 && stridx(l:files[0], "\[No Name\]") != -1
> quit
> endif
> endfunction
>
> Greetings
>
> Axel
No comments:
Post a Comment