Update:
Lexplore
bug mentioned below is fixed (also see the github comment), so you can now use a single mapping to toggle the netrw window:
nnoremap <Tab> :Lexplore<CR>
However, see the comment in the code, repeated invoking of Lexplore
is not the intended use.
Original answer:
There is a Lexplore
command to toggle a netrw window on the left-hand side. However, there is a bug that executing it multiple times will generate a lot of empty buffers.
For now, I think stimulate's answer is quite good. I created my single-function version based on that answer (I am not a vim expert, so not sure if this is better):
nnoremap <Tab> :call ToggleNetRW()<CR>
function ToggleNetRW()
if exists("g:netrw_buffer") && bufexists(g:netrw_buffer)
exe "bd".g:netrw_buffer | unlet g:netrw_buffer
else
Vexplore | let g:netrw_buffer=bufnr("%")
endif
endfunction
<Tab>
! It’s the same keycode as<C-I>
, which by default is a useful navigation command – D. Ben Knoble♦ Mar 18 '20 at 15:25