For example, h,j,k and l move the cursor in VI and they can be mapped to left, down, up and right arrow keys in a browser. This is straightforward and I believe all multi-layered keyboards can do that. The challenge is to take a further step to have
command sequences like "3b" to move the cursor three words backwards, "c2w" to change the next two words, and "ddp" to
swap two lines.
In a browser, there are a set of editing commands to work with. They are basically combinations from {shift, control, left, right, up, down, backspace, delete, home, end, page-up, page-down} plus control-c for copy, control-v for paste, control-x for cut, control-z for undo and control-y for redo.
Take the above VI sequences for example. "3b" can be translated to 3 times of control-left combo. "c2w" becomes control-shift-right twice and switching to insert mode. "ddp" is more like home, shift-end, control-x, end, enter and control-v.
However, the editing commands in a browser don't always work the same way. For example, control-right always moves the cursor to the beginning of the next word in Google Docs but it moves the cursor to the end of the current word or the end of the next word when I'm editing this post. So it's hard to get the exact VI behavior since the keyboard has no idea about the editing box in a browser.
Some VI commands can't be easily translated. For example, the '.' command repeats the last text-altering command, which is super useful in VI. This requires the keyboard to remember the entire editing sequence including the entered text which is unbounded in size. Another example is the 'f' command which finds a character in a line and move the cursor there. It can be done with some finesse around control-f which brings up a search box but I haven't got time to implement it. Its behavior probably is browser-dependent.
Do we have some ardent VI users here? Any suggestions for making this more useful? If you are interested, you can find the firmware at https://github.com/macroxue/keyboard-firmware. The two key files are vi_command.h and vi_translator.h. Quite a lot of commands are there but they are far from all. Here is a cheat sheet for VI commands. Some of them are probably impossible to get right with just keyboard firmware.
