I would like to automatically close the netrw window when I open a file. I've found a similar question (NERDTree How to open a file and automatically close the explorer buffer), but it refers to NERDTree - not netrw.

This is my .vimrc file:

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
set autochdir
map <C-E> :Lexplore<CR>

Edit: This works when using :Explore, but in my case, I'm trying to make it work when I use :Lexplore

  • 3
    Isn't that what happens by default? E.g. I run :Explore, the netrw Directory Listing comes up in the current buffer, I select a file pressing <Enter> and that file is opened in the current window (and netrw is closed)? Jul 19, 2017 at 7:28
  • @ChristianBrabandt when you use :Explore - yes, but I'm using :Lexplore (I don't like when it covers everything) Jul 19, 2017 at 20:19
  • That is an information, that you should have shared in your question. Jul 20, 2017 at 5:28
  • 2
    @ChristianBrabandt My apologies, I assumed it would be obvious from my .vimrc file. Jul 20, 2017 at 5:52
  • Did you find a solution @GiladNovik?
    – user14526
    Mar 19, 2018 at 3:35

1 Answer 1


I think your problem comes from the following line of your .vimrc:

let g:netrw_browse_split = 4

From the doc :h g:netrw_browse_split you can read:

  *g:netrw_browse_split*    when browsing, <cr> will open the file by:
                =0: re-using the same window  (default)
                =1: horizontally splitting the window first
                =2: vertically   splitting the window first
                =3: open file in new tab
                =4: act like "P" (ie. open previous window)

So this should solve your problem:

let g:netrw_browse_split = 0

Otherwise I think you may be able to adapt the autocommand solution from the question you linked since netrw buffers has a filetype set to netrw.

  • 1
    I've just tried to change it to 0 - it still opens in the same window, but netrw still stays open after. Jul 19, 2017 at 20:17
  • 1
    @GiladNovik I just read your comment answering to ChristianBrabandt, the doc also says This option does not affect :Lexplore windows. so indeed that might not be a solution for you.
    – statox
    Jul 20, 2017 at 7:31
  • I'm unsure what the OP means but if you want to close netrw if it's the last buffer, e.g. when you are exiting this file you opened, then see stackoverflow.com/questions/29012106/…
    – Colin D
    May 28, 2019 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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