iTranslated by AI
Building an IME with Vim and asyncomplete.
There is a Vim extension called coc.nvim, which is a Vim plugin that runs as a node.js process by heavily stealing utilizing code from Visual Studio Code extensions. The day before yesterday, I found an extension called coc-rime that can be used from coc.nvim.

Image borrowed from the repository
Apparently, there is an IME called rime which is quite famous in China, and it seems to be using its API. Looking into how it works, I found that it uses a command-line program called rime-cli to interact with rime.
When you provide typed keys to the standard input of this rime-cli program, the conversion results are returned via standard output. I thought this was quite interesting, so I experimented to see if I could achieve something similar with SKK. There were two things needed for the implementation:
- A CLI that returns conversion results when given SKK input
- A function to control this program and act like an IME
I built the former using Go.
By default, it operates in an interactive mode with a prompt, and by adding the -json flag, it switches to JSON-based interaction.

:::message info
To give a brief explanation for those unfamiliar with SKK: it is a Japanese input system developed by Professor Masahiko Sato of Tohoku University (now Professor Emeritus at Kyoto University), with many conversion engines implemented across various platforms. The input method is somewhat unique; because the user manually specifies okurigana and inputs text in short phrases, it features the distinct characteristic of having no misconversions. It remains popular among UNIX veterans and continues to be used today.
:::
For skk-cli, you need to place SKK-JISYO.L in ~/.config/skk-cli/SKK-JISYO.L on UNIX systems. On Windows, it should be at %APPDATA%\skk-cli\SKK-JISYO.L.
Once you confirm that the command works on its own, the installation is successful.
The latter was built on top of a Vim plugin called asyncomplete. The author is Mr. Prabir Shrestha, who also presented at VimConf 2019. He is well known as the author of vim-lsp as well.
Asyncomplete provides an API for creating completion extensions, so I just had to follow that API to build it.
As described in the README.md, you need to configure a key for toggling the IME on and off.
imap <c-\> <plug>(asyncomplete-skk-toggle)
In this case, it is CTRL-\.

Although it's based on SKK, it's not quite practical yet since it lacks features like Kana mode, direct input mode, and a learning function, but I think the experiment can be considered a success for now.
If anyone wants to make it more practical, please feel free to send a pull request.
Discussion