How can I close the Netrw buffer?

I tried both :bd and :bw and neither work.

  • 1
    It's in its own window/pane? :close? – B Layer Dec 22 '17 at 2:16

The autocmd FileType netrw setl bufhidden=wipe still leaves one buffer open. I found this solution, which closes it after opening the file:

let g:netrw_fastbrowse = 0

over at the discussion on https://github.com/tpope/vim-vinegar/issues/13

| improve this answer | |

I've had this problem, when using Vinegar to make netrw easier to use. I found a site that offers one solution here, and more solutions here.

The solution that worked for me, was to add this to my .vimrc:

autocmd FileType netrw setl bufhidden=wipe

For the sake of completeness, other solutions:

@serebrov on Github:

function! QuitNetrw()
  for i in range(1, bufnr($))
    if buflisted(i)
      if getbufvar(i, '&filetype') == "netrw"
        silent exe 'bwipeout ' . i

autocmd MyAutoCmd VimLeavePre *  call QuitNetrw()

@slashfoo on Github:

" Remove 'set hidden'
set nohidden

augroup netrw_buf_hidden_fix

    " Set all non-netrw buffers to bufhidden=hide
    autocmd BufWinEnter *
                \  if &ft != 'netrw'
                \|     set bufhidden=hide
                \| endif

augroup end

The first solution was posted by @tpope, also on github.

| improve this answer | |

typing q while in the buffer closes mine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.