Vim: Delete all buffers
Apr. 8th, 2005 04:14 pmThe following macro deletes all the buffers.
" Check if buffer is in the :ls list. In VIM6, buffers can exist
" without being loaded or listed.
function! Buf_loaded(bufidx)
if version >= 600
return bufloaded(a:bufidx)
else
return bufexists(a:bufidx)
endif
endfunction
" Remove all buffers.
function! Del_all_buf()
let bufidx = 1
while bufidx <= bufnr("$")
if Buf_loaded(bufidx)
execute 'bd' bufidx
endif
let bufidx = bufidx + 1
endw
endfunction
" F12 d removes all buffers.
nmap <F12>d :call Del_all_buf()<cr>
vmap <F12>d <esc>:call Del_all_buf()<cr>
imap <F12>d <esc>:call Del_all_buf()<cr>