Sometimes during my workflow, I might want to open/search for a file on the go. I'd like to map a single key (say F6) to open and close NERDTree (ie. I want to toggle NERDTree view). Also, I'd like NERDTree to display hidden files and folders in its toggled view and I'd also like it to close automatically when I open a file for editing if that is possible. Thanks !
The following function tracks open netrw buffers and calls
Lexplore accordingly. Add it to your
.vimrc and pick your mapping key.
let g:NetrwIsOpen=0 function! ToggleNetrw() if g:NetrwIsOpen let i = bufnr("$") while (i >= 1) if (getbufvar(i, "&filetype") == "netrw") silent exe "bwipeout " . i endif let i-=1 endwhile let g:NetrwIsOpen=0 else let g:NetrwIsOpen=1 silent Lexplore endif endfunction noremap <silent> <F2> :call ToggleNetrw()<CR>