A lot of non-Vim users think of Vim as this impossibly minimal, spartan editor. After all, that’s what you see when you open it by accident or out of necessity. But a while back I saw a couple of coworkers using some IDE that looked really cool and amazingly nerdy, zooming through editing tasks at the speed of light. When I learned they were using Vim, my eyes were opened and I began my journey.
One of the first things that helps make Vim into a more IDE-like experience is some kind of file tree / project view / whatever. Something to let you see and choose your files right from within the Vim. Pretty much every other editor or IDE has such a feature.
The plugin many new users start off with for this purpose is NERDTree. It’s the one I started with and it went a long way to making me feel more comfortable in Vim. If you haven’t tried it yet and you don’t have any other solution for this and this is causing you pain, I strongly suggest checking it out.
There are other options, and in fact (as I’ll explain later) I’m currently using one of those other options. But I’ll cover NERDTree in this article and look at some others in future articles.
Install NERDTree through whatever plugin manager or other system you use to install plugins. It doesn’t give you any shortcuts by default. You can toggle it on and off with
:NERDTreeToggle, but that’s a bit much to type, so make a mapping like:
nnoremap <F2> :NERDTreeToggle<CR>
While you’re in there, make this one, too:
nnoremap <F3> :NERDTreeFind<CR>
F2 will open NERDTree in the directory where you initially started Vim.
F3 will open NERDTree and navigate to the location of file in the current buffer in Vim. Of course, use whatever shortcut keys you want.
Once you’re in there, you can navigate the file system for your project, expand folders, move, rename, create and delete files and folders, etc. Press
? to get a full help view with all the possible commands. And because this is all within Vim, you get neat built-in features like using
/ for searching, visual mode selection for multiple files, etc.
NERDTree is super powerful and if you are not fully comfortable with Vim yet, using NERDTree will very likely help you out a LOT.
However, after using Vim for a while, I started making a lot more use of open buffers and fuzzy searching with FZF and ripgrep. (I’ll talk about both of those in future articles.) As I began relying more on those tools, my need for a full blown file explorer like NERDTree has diminished. I’ve also noticed a few things about NERDTree that have begun to annoy me slightly. One example is if I toggle it open, but then decide to use FZF to search for a file instead, often the file I searched for opens in the NERDTree split. Then I have to do some fancy rearranging to get things back to how I want them. This is not NERDTree’s fault at all. But this, and other similar issues highlight the fact that NERDTree is probably a bit more than I need at this stage.
So I started looking for some more lightweight alternatives that will do what I need, but not get in the way so much. Articles on what I’ve found are upcoming.