Vi clone written in BASIC proves old habits :wq hard

Offbeat

A few hundred lines of Yabasic recreate just enough to keep modal editing muscle memory alive

The veteran editor Vi turns 50 this year, and what better way to celebrate than to write a version in BASIC?

The code was created by Lee Tusman, who
likes to be a little out of step with the latest IT industry fads. Not strictly
a professional programmer, Tusman, whose background is in art, began looking at
BASIC in 2025. Specifically, Yabasic, an open source BASIC interpreter for Unix
and Windows.

“For a modern BASIC, it’s quite fun to use,” Tusman wrote.

“I made my own cyber-hoss racing game, a command line game inspired by the UFO50 and Flash game Quibble Race. I also
tinkered with the internals of the text version of The Oregon Trail, and built
a clone, a simple version of Dope Wars economic simulation game.”

All of which brought Tusman to code up a
version of the veteran text editor Vi, using BASIC because… well… it was
there.

“I’ve been using Neovim (and before
that, Vim) for years and years. I’ve never made a text editor before. But I
decided it could be fun to try to implement my own.”

Inspired by tools such as Offpunk, a text-based
browser, “I thought I could likely build an ULTRA simple editor with a
minimum of Vim commands. How hard could it be?”

In this instance, not too hard at all. It
only took a few hundred lines of Yabasic code to get a minimal blank page
working before Tusman began adding simple commands. Before long, the editor
had reached the point where it was possible to open a file, start a new one,
and save.

“This was satisfying as I was now able
to open the actual code for my vi.bas program and poke around and edit it.”

There’s no wrapping in Tusman’s editor – 80
characters is the limit – but fire up the code from the GitHub repository, and
a reasonable simulacrum of the venerable editor, along with a lot of its sometimes
esoteric shortcuts, runs up.

The Register asked Tusman why he chose Vi. “I chose Vi because I already use it, and of course, once
you’re addicted to it, it’s hard to want to use any other style of editor.”

So what’s missing? “Many things! But
I’m purposefully not trying to rebuild a complete Vim. I just wanted something
usable with as much functionality as I could build in as short and
straightforward a program as I could write. Notably, most of it is ‘if this key
is pressed, do this.'”

As for future development, “I don’t know how much I’d add,”
Tusman said. “I’ve only been using the program a week or so, but
haven’t found much I completely miss from Neovim. I’m speculating here, but
maybe I’d optionally add back in line numbers, and I haven’t found a way to
prevent errors when the screen gets resized that works cross-platform.”

In his post, Tusman notes that while the
code won’t win any prizes for its beauty, it is functional and can be tinkered
with. It’s also in the public domain, and so could be forked if there’s a
function that a BASIC wrangler can’t do without.

A look at the source certainly brought
back some memories for this hack, who cut his teeth on TI BASIC in the very
early 1980s and hasn’t gone near the language since uninstalling Visual BASIC 6
decades ago.

“It’s not only the best Vi clone I’ve
found written in a BASIC implementation,” Tusman wrote. “I think it’s the only one!” ®

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *