Neovim State Machine

Learning the State Machine Behind a Modal Text Editor: The (Neo)Vim Case Study
Pierre Ganty
SPIN 2024, 30th International Symposium on Model Checking Software, 10-11 April 2024, co-located with ETAPS 2024 in Luxembourg City, Luxembourg

PDF

It’s pretty rare to see a paper on text editors in the 21st Century, much less a paper dealing with the “horrendously unusable” “old war horse” vim. I jumped on this one.

Everyone who’s used a vi variant (which vim is) for a little while comes away with the impression that there’s a set of rules for how vim behaves. It feels strict. That notion of “set of rules” is usually formalized in math and computer science as a state machine. Someone named Darcy Parker has made a diagram of how such a hypothetical vim state machine might be visualized.

This paper isn’t about vim really, it’s about some kind of machine learning that can figure out implicit state machines. That’s important because the author perpetuates the “but it’s a modal editor” myth about vim. Ganty gets so close: he gives cfz as an example (“change”, “forward”, (implicitly) to the next ‘z’) as an example of how complicated vim “modes” are, but doesn’t recognize that as concatenated commands. Also, thank you, Pierre Ganty, even though you missed the concatenation of commands, you showed me something about vim I did not know. I use ci( and ci" all the time, now I can add cf_ to my repertoire.

As examples of concatenated vim commands, xp deletes the character under the cursor, which moves the cursor one character to the right, then puts that deleted character after the cursor. It transposes characters. The command x can be used multiple times, xx deletes two characters, or multiplied, 4x deletes 4 characters. The p command can be used on its own, or concatenate: Yp copies a line and puts a copy beneath the current line.

That is, this is an interesting paper from the standpoint of deciphering implicit state machines, but it’s got somewhat mistaken premises and verbiage about text editing.

This paper’s bibliography has a reference to an interesting blog post, Understanding the Origins and the Evolution of Vi & Vim. It’s almost always worthwhile to read a paper’s bibliography to find further things to learn.