Digraphs in Firefox

(as seen in Vim)

What are Digraphs?

I really became addicted to Vim’s digraph feature. It’s a simple but elegant way to input higher Unicode by entering combinations of ASCII characters. In insert mode, you press Ctrl-K followed by a mnemonic two-character sequence and Vim inserts the corresponding character from the digraphs table.

The Wikipedia has an article about different input methods on several OSes and programs. In my opinion, the digraphs are one of the most elegant.

All existing digraphs in Vim can be listed with the :digraphs command. With two minor exceptions this table corresponds to all the two-letter digraphs standardized in RFC 1345.

I Want them in Firefox!

Now, as long-term Firefox user I caught myself more and more often to press Ctrl-K when trying to enter text in inputs or textareas. Obviously, the outcome was not the intended. The command either focuses the search form next to the address bar or, if that doesn’t exist, opens the website that is connected with the default search (in my case a branded Google form).

Firefox addons come to the rescue. Well, at least I thought, that someone would have had the same problem before. But it seems, that everyone who could be potentially interested in this feature already uses Vimperator (which, ironically, seems to omit it).

So I rolled up my sleeves and finally wrote my first ready-to-use Firefox addon. It’s called Digraphs and lives (momentarily) at Github. Of course it has much potential for improvements, but in its current state it already is quite useful.

The Details

It works just like digraphs in Vim. Intercepting the keypress event it listens for Ctrl-K keystrokes. If it finds one, the next two keystrokes are catched as well and compared to the RFC 1345 list.

If a match is found, the Unicode character is issued via a generated KeyEvent. If not, the last entered character is left through. This fallback mirrors Vim’s behaviour.

Can I Test It?

Of course! If you just want to see, how the digraph feature works, I made a demo page, where you can visually explore the wonders of RFC 1345.

What will be Next?

The addon lacks preference options. Two come to mind immediately:

  1. the possibility to convert the firing keystroke from Ctrl-K to something else, and
  2. custom digraphs to extend the original list.

As I wrote, this is my first Firefox addon, so I’m still in the process of figuring out everything. But as soon as I know how to do that, I’ll add these options.