Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Using Vim as an input method editor (IME) for X11 apps (github.com/algon-320)
132 points by algon on Dec 4, 2022 | hide | past | favorite | 27 comments
As a Vim user, I often use Vim to write some text and then copy & paste it into another text field of GUI apps (e.g. browsers, chat apps, etc.), because almost all of these text fields provide only very basic editing functions.

A while ago, I came up with an idea: what if we could use Vim as an IME?

Ordinary IMEs are used to input some non-English characters, but the essential functions of IME are 1) receiving a keyboard sequence 2) process the key sequence and outputting a text

These functions are the same as text editor's. So I thought implementing an IME that can be used with Vim keybindings could be a good solution for the above problem.

After that I learned mechanisms of IME for Linux desktop and tried to develop an experimental IME.



Thank you for sharing this, and for providing a way to use other editors--I can't wait to try it with an Emacs client! (I had something similar in the past with just Firefox; I love the idea of being able to access it from anywhere!)


Alternatively you might want to try Emacs everywhere[1].

[1]: https://github.com/tecosaur/emacs-everywhere


Thank you for the delightful comment! If you find any issues or ideas of improvement, please let me know.


Please check out firenvim, which accomplishes this very useful trick in a site-configurable manner and is compatible with Tridactyl.

https://github.com/glacambre/firenvim


That only replaces <textarea>s. Theoretically the OP project would also work in <div contenteditable>s.


And (more significantly surely?) outside the browser.


On OSX w/ Chrome I use wasavi[0], an extension that implements a nice subset of vim directly in the text area (much like OP's system, but not using actual vim). Works really well, better than other extensions I've tried that attempt to ~shellout to $EDITOR and then sync back to the input area.

[0] https://github.com/akahuku/wasavi


Wow, that brings back memories...

Back in the '90s I had made an X Input Method that used vim -- essentially forked a gvim process on a temporary file and read the file upon termination. It was a nice learning experience, but not very useful.

Besides textareas in browsers (the main use, where a number of other solutions currently exist), a fun demo was to use vi for changing formulas in a spreadsheet (I assume it must have been StarOffice back then).


Very interesting, I am sure that if something like this is packaged in Linux distros would become popular.


See also: vi keybindings for GTK2/3: https://github.com/polachok/gtk-vikb (not an active project though)


Any experience with this? I would suspect that it would work with GTK2, but not for current GTK3/4.


I was actually the one who submitted patches for GTK3 support! But, yes, it's never going to work with GTK4, at least not without complete overhaul.

I don't daily-drive it though, mostly because I never found time to update rather limited set of keybindings, a task that seems way more involving than a couple of little fixes that were needed to support GTK3.


Tridactyl can also do this for text input fields in firefox (:editor).


qutebrowser too; I have it bound to ^E


This is blackmagic. Nice work!

Q: Why not publish it to crates.io (cargo publish)?


How difficult would it be to port it to Wayland?


I'm not familiar with how IMEs work in Wayland at the moment, but I guess it is possible by the similar way as XIM. I would like to investigate the protocol later.


This is brilliant. Now if I could only get IMEs to work for more than a few weeks before they break...


Really cool; thank you for sharing!

Curious: Did you consider neovim over vim and if so what made you stick with vim? AAUI neovim has these kinds of "embedded" use-cases in mind and intends to be smoother than vanilla vim.


Thank you for the information. Actually I didn't so stick to vanilla Vim and have no intention to avoid Neovim at all!

FYI, since this IME embeds a terminal emulator it should be able to use with other terminal-based editors (including Neovim) by applying almost no changes to the editor's codebase.


Looks so good. Is it compatible with Neovim?

Thanks for sharing!


Will this let me use vim bindings in Google docs?


Love it, and the video. Will install tomorrow.


I have been expecting this for long


Oh hell yes.


Depressing to think that, even if you find a way to make this work, it'll be deprecated in a few years as most distros move to Wayland. Then if you figure it out in Wayland, it'll probably break again when they come up with some new backwards incompatible bullshit. Everything in desktop Linux is like this.


You say that like desktop Linux is new, or we only just switched to X11.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: