Trevor Stone (flwyd) wrote,
Trevor Stone

  • Location:
  • Mood:
  • Music:

conjoin: A Vim Plugin for Continuation Characters

As an avowed introvert, I took the opportunity of the new fewer-social-commitment world of coronavirus stay-home orders to do some fun programming on personal projects, like my Elizabethan curse generator. While working on bash and Tcl implementations I discovered that vim, my favorite text editor, did not automatically remove line continuation characters when performing a join command. In my case, I had copied an array of quoted strings from Python into a shell script, which doesn't need quoted strings, and wanted to realign the declaration to fit nicely in 80 columns, like so:
noun=(apple-john baggage barnacle bladder boar-pig bugbear bum-bailey \
canker-blossom clack-dish clotpole coxcomb codpiece crutch cutpurse \
death-token dewberry dogfish egg-shell flap-dragon flax-wench flirt-gill \
foot-licker fustilarian giglet gudgeon gull-catcher haggard harpy hedge-pig \
hempseed horn-beast hugger-mugger jack-a-nape jolthead lewdster lout \
maggot-pie malignancy malkin malt-worm mammet manikin measle minimus minnow \
miscreant moldwarp mumble-news nut-hook pantaloon pigeon-egg pignut puttock \
pumpion rabbit-sucker rampallion ratsbane remnant rudesby ruffian scantling \
scullion scut skainsmate snipe strumpet varlot vassal waterfly whey-face \
whipster wagtail younker)
Unfortunately, the J command in vim leaves those trailing backslashes (which mean "the command keeps going on the next line") in the middle of the combined line. After a bunch of Googling, I determined that there wasn't a vim setting to do so, and nobody had written a plugin for it either.

So of course I decided that extra home-bound free time meant it was time to learn how to write a vim plugin so that I could change the behavior of the line-joining commands. A couple coworkers mentioned that such a plugin would be even more useful if it could merge strings when joining as well (resulting in "lorem ipsum" rather than "lorem " + "ipsum"). This in turn provided a great excuse to geek out on programming language details on Wikipedia, Rosetta Code and And thus was born vim-conjoin, a plugin that remaps J, gJ, and :Join to handle continuation breaks and string concatenation.

This exercise was absolutely a violation of XKCD's Is It Worth the Time graph: I spent the better part of two weekends, plus a few evenings, implementing and testing this plugin (mostly testing). It will, in my lifetime, perhaps save me an hour of work. So hopefully other vim users find it useful, too.

As with any personal programming project, the time wasn't entirely wasted, of course. The next time I want to write a vim plugin I'll have a much better idea of what I'm doing. And I learned more in a couple weeks about vim than I've learned in most individual years in the last two and a half decades I've used the editor. (Though it's going to take me awhile to remember to put call before function invocations and I'm forever forgetting the l: and a: prefixes on local and argument variables.) And the Wikipedia adventures led me to finally read up on INTERCAL a famously obtuse parody language, and LOLCODE, a lolcat-inspired esoteric programming language that I wish I'd heard about in 2007 when it was announced. (LOLCODE unfortunately seems to have been abandoned; the language author hasn't responded to a 2018 proposal for array (BUKKIT) syntax.) And that gave me an idea for an esoteric language of my own that I hope to work out during the remainder of quarantine time…

You do you. And make sure you've got an unnecessarily polished tool while doing so.

This entry was originally posted at – comment over there.

Tags: coronavirus, covid-19, editor, programming, vim
  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.