I have an "almost" perfect netrw workflow. With my internet search, I:

  • Solved <C-l> problem;
  • Splits Right/Bottom (without resize netrw);
  • Toggle netrw (but has an issue);

In my workflow, I like to keep some directories expanded. It helps me a lot. But, when I toggle netrw, all exanded directories are closed and I have to open one by one. If I toggle again, it closes again.

There's a way to keep netrw tree expanded, even after toggle (like NERDTree)?

PS.: Now I'm using NERDTree, but, I would like to use less plugins... Vim already has a file explorer, then, I would like to use it.

Below my netrw setup:

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_winsize = 20

function! OpenToRight()
  :normal v
  let g:path=expand('%:p')
  execute 'belowright vnew' g:path
  :normal <C-l>

function! OpenBelow()
  :normal v
  let g:path=expand('%:p')
  execute 'belowright new' g:path
  :normal <C-l>

function! NetrwMappings()
  " Hack fix to make ctrl-l work properly
  noremap <buffer> <C-l> <C-w>l
  noremap <buffer> V :call OpenToRight()<CR>
  noremap <buffer> H :call OpenBelow()<CR>

noremap <silent> <C-f> :call ToggleNetrw()<CR>

augroup netrw_mappings
  autocmd filetype netrw call NetrwMappings()
augroup END

" Allow for netrw to be toggled
let g:NetrwIsOpen=0
function! ToggleNetrw()
  if g:NetrwIsOpen
    let i = bufnr("$")
    while (i >= 1)
      if (getbufvar(i, "&filetype") == "netrw")
        silent exe "bwipeout " . i
      let i-=1
    let g:NetrwIsOpen=0
    let g:NetrwIsOpen=1
    silent Lexplore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.