Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - Quit/Close Netrw without selecting any file

Tags:

vim

netrw

My question is fairly simple, still I can't find the answer anywhere : In Vim, how can I close Netrw explorer without actually selecting a file? What keystroke should I hit to close the explorer and go back to the currently opened file?

So far, I have to select the currently opened file from within Netrw if I want to get back to it, which happens to be impossible if I haven't saved it yet.

I may add that I RTFM, and do know the :h netrw command ;)

Many thanks.

like image 326
Alexandre Bourlier Avatar asked Dec 29 '14 15:12

Alexandre Bourlier


4 Answers

Use <c-6>/<c-^> to go back to the previous buffer. See :h CTRL-6.

Pro-tip: use :Rex to resume exploring. See :h :Rex

like image 84
Peter Rincker Avatar answered Oct 03 '22 07:10

Peter Rincker


Create the below function:

function! s:close_explorer_buffers()
    for i in range(1, bufnr('$'))
        if getbufvar(i, '&filetype') == "netrw"
            silent exe 'bdelete! ' . i
        endif
    endfor
endfunction

Add mapping:

nnoremap <C-e><C-x> :call <sid>close_explorer_buffers()<cr>
like image 41
wisefool Avatar answered Oct 03 '22 07:10

wisefool


Vim by default, without plugins etc., should treat netrw windows like buffers (without listing it like one (:ls or :buffer). Try:

:bd
:bdelete

or

:bw
:bwipe

Peculiar way Vim did not list the netrw windows as buffer, but close it like one, and went back to former buffer/file.

like image 34
Emil Asmussen Avatar answered Oct 03 '22 08:10

Emil Asmussen


With v153 of netrw, one may use :Rex to return to the netrw buffer; it will also permit you to return to the file being edited prior to editing a directory. (see http://www.drchip.org/astronaut/vim/index.html#NETRW for the latest netrw).

like image 45
user21497 Avatar answered Oct 03 '22 08:10

user21497