equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.85k stars 171 forks source link

Auto-disable IME in normal mode and re-enable it when go back to insert/replace-mode #252

Open hh9527 opened 7 years ago

hh9527 commented 7 years ago

This is very useful for editing no-western text document. (for example: markdown files) VIM has already support this feature for many years.

zeGolem commented 2 years ago

I know this is an old issue, but I'd also really like support for this.

Using fcitx+mozc on linux for my part. I think QInputMethod can be used to support this.

jgehrig commented 2 years ago

@zeGolem If you're willing to help, we may be able to get this working!

Two approaches:

  1. If you know how to fix this with QInputMethod, I'm happy to review and merge a pull request.
  2. If you can provide some testing and scenario guidance, I may be able to write the code.

I'm an English speaker, so I'm not very familiar with non-western input methods...

It would be helpful to understand specific setup instructions: keyboard layout, key sequences, observed vs expected behavior etc.

zeGolem commented 2 years ago

I don't really know much about Qt, only started messing around with it recently, but I can maybe try to take a look at the code later… In the meantime, here are setup instruction for the IBus Input Method Framework, with the mozc IME for Japanese input. You can read more on the ArchWiki pages for IBus and Mozc

  1. Install ibus, and ibus-mozc from your distro's repositories
  2. Set up your environment variables:
    export GTK_IM_MODULE=ibus
    export QT_IM_MODULE=ibus
    export XMODIFIERS=@im=ibus
  3. Start IBus: ibus-daemon -drxR
  4. Set up IBus:
    1. Run ibus-setup
    2. In the first tab, set a keyboard shortcut for "Next input method". This is the keybind you'll use to turn on the IME.
    3. Go to the "Input Method" tab
    4. Click on "Add", and select your default keyboard layout, so first select "English" for the language, and then pick the correct layout for your keyboard.
    5. Add a second input method, this time select "Japanese" for the language, and "Mozc" for the layout.
  5. Start neovim-qt in the terminal you used for setting the environment variables.
  6. Go into insert mode, and use the "Next input method" keyboard shortcut. This should switch your keyboard to Japanese. Typing "aaa" should show up a "あああ". Pressing the enter key should dismiss the word selection panel, and confirm the input.
  7. Now, press "esc" to go back into normal mode. You can't move your cursor around using hjkl (or do anything for that matter, as no input is being sent to neovim-qt), because the keys are being sent to the IME (you should see the word selection panel pop up again).
  8. Using the "Next input method", you can move in normal mode.

These last two steps show the issue. Ideally, when in normal mode, neovim-qt should skip the IME and read directly from the keyboard, so that you don't have to manually switch the IME on and off every time you go in and out of insert mode.

Hope these instructions were clear enough, and you understand the problem better. Thank you for your time, if you need any more help with the setup, let me know. I really hope this problem can be solved, it'd make taking writing in languages that require IMEs much easier.

If you get something working with IBus, I can try it on my setup using fcitx5, I think if it works on one, it should work on the other as well, but if it doesn't, I think I'd be able to adapt your code for it. If you want to try to setup fcitx5 with mozc, there is this video showcasing how to do it on ArchLinux: https://www.youtube.com/watch?v=lJoXhS4EUJs

jgehrig commented 2 years ago

[Delete]

Weird... GitHub double posted.

jgehrig commented 2 years ago

@zeGolem

Those are EXCELLENT instructions! That is exactly what I was looking for...

I will work on getting a test environment set up, and I will report back in a few days with an initial investigation.

zeGolem commented 2 years ago

Hi, did you manage to get your testing environment set up?