Improve the toggling of the netrw Explorer
David Blume

David Blume commited on 2021-04-06 19:12:11
Showing 1 changed files, with 4 additions and 7 deletions.

... ...
@@ -123,19 +123,16 @@ nmap <C-p> :pu<cr>
123 123
 
124 124
 " Make netrw's Explore behave a little like NERDTreeToggle
125 125
 " http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
126
-let g:NetrwIsOpen=0
127 126
 function! ToggleNetrw()
128
-    if g:NetrwIsOpen
127
+  if bufwinnr("NetrwTreeListing") > 0
129 128
     for i in range(1, bufnr("$"))
130 129
       if (getbufvar(i, "&filetype") == "netrw")
131 130
         silent exe "Bwipeout " . i
131
+        return
132 132
       endif
133 133
     endfor
134
-        let g:NetrwIsOpen=0
135
-    else
136
-        let g:NetrwIsOpen=1
137
-        silent Explore %:p:h
138 134
   endif
135
+  silent Explore %:p:h
139 136
 endfunction
140 137
 nmap <leader>e :call ToggleNetrw()<cr>
141 138
 
... ...
@@ -318,7 +315,7 @@ endif
318 315
 " Settings that make netrw more like NERDTree
319 316
 let g:netrw_banner = 0
320 317
 let g:netrw_liststyle = 3
321
-let g:netrw_browse_split = 4
318
+" let g:netrw_browse_split = 4
322 319
 let g:netrw_altv = 1
323 320
 " let g:netrw_winsize = -28 (for absolute width)
324 321
 let g:netrw_winsize = 35
325 322