iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🍵

I Created an Ultra-lightweight File Explorer for Vim

に公開

The other day, @lambdalisue wrote an article introducing filer plugins for Vim.

2020 Autumn Comparison of Filer Plugins for Vim | Zenn

I used to use a plugin from that list called dirvish.

Big Sky :: Switched Vim filer from NERDTree to dirvish.

The main reason I used dirvish was that it is "ultra-lightweight." The reason I don't use netrw is, for one, the source code isn't maintainable, and another is that it's just too fat.

My Ideal Filer

Everyone has their own opinion on this, and it's natural for them to differ, so this is strictly my personal view. What I look for in a Vim filer is simply:

  • I want to open the filer with :e /path/to/
  • I want to open the filer with $ vim /path/to/
  • I want it to display the file list quickly

That's it. If possible, I want to think only about the program while I'm programming. So, my opinion is that it's enough if I can edit a file from the list in the currently running Vim; I don't need features like copying or renaming.

Were there no other options?

As candidates, dirvish and vaffle were close to my ideal.

Reasons for giving up on dirvish

The reasons I decided to give up on dirvish are as follows:

  • Hijacking (disabling netrw and hooking into :e /path/to/, etc.) occasionally breaks.
  • The author is too busy maintaining Neovim to maintain dirvish.
  • I don't like the search interface.

I particularly couldn't get used to the third point; it adds unnecessary bits to make the / search the forward part.

Why I didn't choose vaffle

The reasons I didn't choose vaffle are as follows:

  • Even vaffle had too many features.
  • The current directory was in a protocol format (e.g., vaffle://0/C:/path/).

The latter was particularly problematic for me. In my case, I have a keymap that completes the current path (buffer name) when I type <CTRL-x> in the command line. It's a problem if vaffle:// is included at that time.

cnoremap <c-x> <c-r>=expand('%:p')<cr>

For example, I use it for purposes like typing :!rm , then typing <CTRL-x> to enter the filename, so it absolutely needed to be a real path.

If it doesn't exist, build it

If it doesn't exist, I have no choice but to build it. Last night, while searching for an alternative to dirvish, I started creating one.

https://github.com/mattn/vim-molder

It is a filer that truly does nothing. Unlike other filers, it does not have the following features, and I don't think I will include them in the future:

  • Feature to create directories
  • Feature to rename files
  • Feature to delete files
  • Mechanisms to pipe files to a shell

All it has is:

  • It can display a list of files
  • You can move up a folder with -
  • Pressing Enter on a folder moves inside it
  • Pressing Enter on a file opens it in that Vim

That's it. By the way, regarding the name molder, I wanted to rip off how dirvish took the dir from directory, so I thought about dirty and various other things, but couldn't think of a good one. In the end, I punned folder into molder. (Molder, you're tired.)

However, once I started building it, several people from vim-jp showed interest and gave me requirements like "I want to create directories." This differed from my policy for molder. So, I implemented a mechanism to load external plugins into vim-molder, making it so those features are available only when an extension plugin is loaded.

https://github.com/mattn/vim-molder-operations

If you include this plugin together, you can perform simple file operations like creating, deleting, or renaming directories as mentioned above.

Going forward...

For now, by creating my own filer, I've managed to cut my dependency on dirvish. If there's any behavior I don't like, I can just fix it myself, which has made things much easier.

It has few features and I don't plan to expand the main body, so maintenance will likely focus on bug fixes. But if you're interested in this kind of "ultra-lightweight filer," please give it a try.

Discussion