Skip to content

Commit

Permalink
Trying to remove netrw buffers from buffers list
Browse files Browse the repository at this point in the history
Add experimental workaround to remove netrw buffers from the buffer
list.

This happens when using vinegar to navigate the directory of the current
file: the netrw buffers may stick around unclosed [1], or the first
netrw buffer will be part of the list of buffers [2]. It is annoying to
navigate buffers with buffergator or ctrlp when there are several netrw
buffers listed along with the open files.

Try setting the bufhidden option to delete the netrw buffers, and use a
custom function to delete that first netrw buffer that is not removed
just by setting bufhidden.

[1] tpope/vim-vinegar#13
[2] tpope/vim-vinegar#74
  • Loading branch information
smancill committed Mar 2, 2018
1 parent be810ec commit 621522a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions after/ftplugin/netrw.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
" nertrw.vim: settings for netrw buffers

setlocal bufhidden=delete

if !exists("*s:BDeleteNetrw")
function! s:BDeleteNetrw()
for i in range(bufnr('$'), 1, -1)
if buflisted(i)
if getbufvar(i, 'netrw_browser_active') == 1
silent exe 'bdelete ' . i
endif
endif
endfor
endfunction
endif

augroup netrw_buffergator
autocmd! * <buffer>
autocmd BufLeave <buffer> call s:BDeleteNetrw()
augroup END

1 comment on commit 621522a

@karlek
Copy link

@karlek karlek commented on 621522a May 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.