Introducing viutils
Following my switch to a plain vi implementation (see the post about
this), I’ve mostly been satisfied, but there were a number of
gaps I had to fill almost immediately. At first, I had inlined some mappings into my .nexrc file,
but this fell apart as soon as I started to work on a number of different file types. I hacked
together a few scripts to support what I needed, and now I’ve published these so that I can grab
them later. You can find the repo here.
Firstly, I was very surprised at how dependent I had become the gq behavior in vim. This
operation, which “folds”/“reflows” text to a sane column width, seems so superficial when I think
about, and yet in the five years I’ve been using it, it turns out that I’ve been using it
everywhere. I use it to make prose more manageable, sure, but I also use it a lot when I’m writing
code comments. I was very surprised to learn how much nuance there is in this behavior, which vim
had been handling behind the scenes for me. For starters, indentation is a nightmare. I opted to use
pandoc for this since it understands the hellish implicit markdown rules. It gets more complicated
when we start to reflow code comments, though. Code comments almost always have a prefix, and thus I
can’t use the same utility. fmt(1) does the trick, but unfortunately it requires GNU’s
“extensions” to fmt(1). I use quotes there because I don’t believe this is a utility defined by
POSIX, so implementations can pretty much do whatever they want.
The next thing that I ran into was adding shortcuts for running linters. I’ve historically used
<Leader>-r for this (in my mind, “leader” + “rubocop” since that was my day job) and I slowly
added more and more autocmd rules to change the linter that runs depending on the file extension.
This was very simple to handle in a script, but unfortunately this indirection is wholly necessary
in order to support different “contexts.”
Finally, in the past six months, I had started to rely on vim’s spell checking integration. This
would helpfully highlight misspellings in red, and offered some helpful keybindings to run through
each occurrence in the file. Obviously, this is not remotely possible to support in vi, given that
vi does not have syntax highlighting in the vast majority of implementations, much less a way to
dynamically highlight words. After some flailing around thinking about this, I settled on a
relatively simple solution: I can just delimit misspellings in plaintext (I opted for surrounding
typoes with %% e.g. %%mipspelling%%). This has the unfortunate side effect of mutating the
buffer, but it’s universal, and my new habit is to run this over a paragraph and then undo after
I’ve read through the flagged words.
That’s all I’ve done for now, though I’ll probably have some sort of “quickfix”/search hack in the next month or so. This has been less urgent, but I’ve definitely missed the ability to dump hundreds/thousands of matches into a buffer and quickly run through them. I rarely need this on tiny codebases, but anything beyond that becomes painful without a mass search option.