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.
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>
if exists("g:netrw_buffer") && bufexists(g:netrw_buffer)
exe "bd".g:netrw_buffer | unlet g:netrw_buffer
Vexplore | let g:netrw_buffer=bufnr("%")