Vim Foot Pedal

Posted on June 7, 2020

A while ago, I read this writeup (found via Boing Boing) of using a USB foot-pedal to toggle between Vim’s command & insert modes.

While I’m not a fan of overthinking my text editor config, I am a fan of unusual IO devices, and I own a 3d printer and (prior to this project) a spare teensy 2.0 microprocessor, so this weekend, I thought I’d try to throw together my own vim foot-pedal.

Initially, I expected to be able to find a suitable foot-pedal on thingiverse. However, because I was keen to use micro-switches (I had a whole bunch spare), I couldn’t find a design on that I liked that wouldn’t require a bunch of modifications.

Since I have my own pet Haskell CAD Framework, I chose to use that. You can find the source-code for this pedal here. It’s a pretty simple design: the bottom half houses the teensy and the micro-switch, and the top half is attached using two M5 bolts that act as a hinge. A couple of 3d printed springs add a little bit of extra resistance to the micro-switch.

If I was making another one of these, I’d increase a lot of the wall thicknesses, particularly on the bottom. At the moment, it’s just a little flimsy. Similarly, I’m not particularly happy with the top half from a design for 3d-printing perspective: I couldn’t find a way to orient it on the printer that didn’t require a shed load of support material to print, and as a result of printing on top of support material, some of the surfaces aren’t great, which shows up in the photos.

The software on the Teensy is a pretty standard Arduino program. I’m using Teensyduino to run the Arduino stack on a Teensy. Despite the fact that this was relatively straightforward, it reminded me how much I dislike firmware projects; anything that requires editing udev rules isn’t worth doing.

In contrast to the original article, I found that sending 'a' rather than 'i', when the pedal is depressed works better. 'i' inserts at the cursors current position, while 'a' inserts after the cursor. The practical result of this is if I want to type “hello-world” and I do the following:

  • depress the pedal
  • type "hello"
  • release the pedal
  • depress the pedal again
  • type "-world"

With 'a', I get:

hello-world

Whereas with 'i' I get:

hell-worldo

With the second block of text inserted before the last character of the first block.

To be honest, I suspect that creating 'i' and ESC keystrokes is not ideal in the first place, and I really want to have the foot-pedal act as a single button, and configure vim to get the behaviour that I want. With that said, I opened this blog post saying “I’m not a fan of overthinking my text editor config” and I quite like the idea of this pedal being plug-and-play.