Last Updated: November 09, 2021
· 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'
      exec cur_win_nr . 'wincmd w'
      unlet t:expl_buf_num
      unlet t:expl_buf_num
    exec '1wincmd w'
    let t:expl_buf_num = bufnr("%")

"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:
That said, I don't know if they copied someone else :P

over 1 year ago ·