randomfox (randomfox) wrote,
randomfox
randomfox

Vim: Delete all buffers

The 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>

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments