Last Updated: November 09, 2021
·
1.846K
· akagr

Swap NERDTree for Vim's Netrw explorer

NerdTree is a fantastic vim plugin. But for me it was a bit overkill because all I needed was to view directory tree and open files. It also made me feel sad for built-in (and very functional) explorer. Here's a quick addon to my vimscript for easy toggling of the default explorer.

"Toggles explorer buffer
function! ToggleVExplorer()
  if exists("t:expl_buf_num")
    let expl_win_num = bufwinnr(t:expl_buf_num)
    if expl_win_num != -1
      let cur_win_nr = winnr()
      exec expl_win_num . 'wincmd w'
      close
      exec cur_win_nr . 'wincmd w'
      unlet t:expl_buf_num
    else
      unlet t:expl_buf_num
    endif
  else
    exec '1wincmd w'
    Vexplore
    let t:expl_buf_num = bufnr("%")
  endif
endfunction

"Set default width of explorer to make it appear like a sidebar. Also defaults to tree style.
let g:netrw_liststyle=3
let g:netrw_winsize=20

"Lastly, set a key mapping for calling the function above
noremap <silent> <C-E> :call ToggleVExplorer()<CR>

I picked it up off net a long time ago and have really forgot where I got it from. Kudos to whoever wrote it :)

PS: I use ctrlp.vim primarily for quickly opening files and managing buffers. Sometimes, you just have that itch to see the directory tree though.

1 Response
Add your response

Sorry for bumping a two year old post, but I think I found the original: https://coderwall.com/p/p6pddw/swap-nerdtree-for-vim-s-netrw-explorer
That said, I don't know if they copied someone else :P

over 1 year ago ·