After my first few weeks at Mozilla, diving back into vim as my full-time editor and using Searchfox heavily, I got the idea to write a plugin to make it easier to search directly from vim.

I started using vim in 2013 and almost immediately started using plugins. I’ve whittled down my .vimrc to a core set of them by now, but I’ve always wanted to write one for… something. It had to be something I would actually use, but also something that someone else might benefit from.

After ~8 months of occasional spare-time tinkering, here’s the result: vim-searchfox

There are three commands:

  1. :SearchfoxFile - Opens the Searchfox source for the active buffer’s filename.
  2. :SearchfoxFileLines - Like the previous command, but intended for use in Visual mode: highlighted lines will also be highlighted in Searchfox.
  3. :SearchfoxSearchText - Also for use in Visual mode, instead of opening the current file in Searchfox, it’ll perform a search for highlighted text.

The resulting URL will be opened in the default browser, as well as copied to the keyboard. I’d like to add configs to toggle these features on and off as desired. (I strongly suspect the open bits don’t work well on Windows, but I haven’t had the chance to investigate.)

Resources

I had to learn a lot about vimscript while writing this, and these resources were incredibly valuable:

This guide to vim script for those of us from a JS background was indispensable

Learn vimscript the hard way by Steve Losh was also a useful reference