File Management in Vim: netrw/vim-vinegar

As mentioned in the last article, the NERDTree plugin helped me tremendously to feel comfortable when I was first starting out in Vim. It was the first step in making Vim feel more like a “real” editor or IDE and not some ultra-minimal command line tool.

But as I got more used to using existing buffers and fuzzy file searching, NERDTree started becoming less and less useful and at some point started getting in my way as much as it was helping me. That’s not a dig on NERDTree at all. It was just time for me to adjust the tools I was using to my current skills and workflows.

The first things I tried were netrw and vim-vinegar. netrw is a plugin that is built right into Vim. and vim-vinegar is built on top of netrw. Also, NERDTree hijacks some of netrw’s functionality, so if you have NERDTree installed, you should at least temporarily disable or uninstall it if you want to test out the stuff I’m talking about here today.

netrw is a much more minimal file manager. You can open it by typing :edit . or simply :e.. Or make a mapping for that like <Leader>e or whatever. Because . is a directory, not a file, it opens in netrw to let you browse that location. Another useful shortcut to make is for :Explore or simply :E. This is a lot like NERDTreeFind in that it opens to the location of the file in the current buffer. You might want to map that to <Leader>E or whatever makes sense for you.

The first thing you’ll notice is that netrw opens as a full window, not a split like NERDTree. And when you choose a file, it goes away automatically. If you really like the idea of the IDE-like file explorer stuck to the side of your editor, you may just want to stick with NERDTree. But this more ephemeral file management tool was just what I was looking for.

Up at the top, there’s a big header showing a bunch of information about where you are, what’s being filtered and how things are sorted, and some helpful shortcuts. You can do :help netrw to find out about a whole lot more shortcuts.

Like NERDTree, you can traverse the file system, open files directly, or in splits or tabs, preview, etc. You can create or delete files or directories. Again, see the help on how to do all this. And also like NERDTree, you can search with / and do visual selection, etc.

If you like netrw, but want a bit more, check out vim-vinegar by Tim Pope, one of the kings (THE KING) of Vim plugins. It adds a bunch of neat enhancements on top of netrw. It gives you the shortcut of - to open directly to the location of a file. It hides that top banner (it’s still toggleable). It lets you type . or ! to copy a file name to the command line area for performing other operations on a file. And some other neat things. Definitely worth checking out.

While netrw was much more of a fit than NERDTree for me, I still found a few annoyances. The main one is that once you open netrw, it creates a buffer that you cannot easily close. This is a known bug and there are various workarounds for it, but none that worked particularly well for me. I always had that netrw buffer hanging around. And since my workflow is heavily focused on open buffers now, this was really annoying. Note, that this is a netrw issue, but because vim-vinegar is a direct enhancement of netrw, it inherits the same issue.

However, this may or may not be that annoying to you. Try netrw out. If it works for you, and you like it better than NERDTree, then great! If you wind up having the same issues I had, stay tuned for the next article, which discusses the solution I’ve arrived at so far.

Update

I figured a workaround for the issue described in the end of this article. You can find that in this article. With that workaround in place, I find that plain vanilla netrw works really well for me and that’s what I’m currently using.