It happens every few years: I get tired of Vim, I try another editor, I get proficient in said editor, then for no reason at all I go back to Vim. Familiarity? Comfort? Masochistic? Don’t know. But like a dog returns to its vomit, I return to Vim. And I love it all over again.
This round with Vim has been accompanied by lots of customization. Things like a custom status bar that changes colors depending on whether I’m in insert or command mode and an emacs-like “scratch” buffer that I can call up whenever I want with a few keys. Lame-o, I know, but I felt like each was quite an accomplishment. I haven’t customized Vim like this ever in the 17 years I’ve been using it so pfffthththtthh.
My latest effort, again for no particular reason other than “why not”: ditch NERDTree, the file explorer plugin favored by recent Vim converts, and use the built-in netrw functionality instead.
I never thought it could be possible to do this, but hey, turns out it works.
Tonight, I stumbled upon a StackOverflow webpage that details how to mimic a lot of NERDTree’s functionality (at least the stuff I used in NERDTree) using netrw. It mostly boils down to including the following code in your ~/.vimrc file:
" Toggle Vexplore with Ctrl-E
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'
exec '1wincmd w'
let t:expl_buf_num = bufnr("%")
map <silent> <C-E> :call ToggleVExplorer()<CR>
" Hit enter in the file browser to open the selected
" file with :vsplit to the right of the browser.
let g:netrw_browse_split = 4
let g:netrw_altv = 1
" Default to tree mode
" Change directory to the current buffer when opening files.
The “Default to tree mode” bit near the bottom was added by Yours Truly. It’s important to me for no reason other than I like collapsible trees better than netrw’s default mode.
As the code above says, hitting CTRL-E opens/closes the netrw tree. Highlight a file and hit ENTER and the file will be loaded in a window to the right of the netrw window. Hit CTRL-E again and netrw goes away. Lather, rinse, repeat.
So, so cool. I love ditching plugins, and NERDTree was always a bit of a pain in the ass. It never installed cleanly, it doesn’t work at all with Pathogen (a Vim plugin manager) in spite of claims to the contrary…goodbye. I’m a happy hippo again.