Skip to content

vim extension issue with Chinese IME #8133

Closed

Description

@localvar
  • VSCode Version: 1.2.1
  • OS Version: Windows 10 professional

I tried two Vim extensions, amVim and VsCodeVim, both have problems when using Chinese IME:

from the comments of the issues: it is not only affect Windows, but also OSX and Linux; and not only Chinese, but also Japanese.

So, it is highly suspect this is an issue of VSC instead of the extensions.

Activity

  1. rebornix commented on Jun 25, 2016

    @rebornix
    Contributor

    The reason this issue comes with Vim extensions is because Vim needs to monitor user's keyboard input and all these extensions are listening to type command, but it's working in a strange way.

    Let's say users want to type in a Chinese word 安 and in Chinese IME, they should type a + n then in their IME popup window, choose the first word by pressing 1 or space. Currently if you monitor type command, only a is emitted by VS Code.

    So ideally, if users type an1 in Chinese IME, VS Code should only pass 安 to type command listeners.

  2. fenbox commented on Jul 8, 2016

    @fenbox

    Hope this can fix soon, it's terrible for Chinese (reference above)

  3. freshcn commented on Jul 8, 2016

    @freshcn

    +1

  4. Yukaii commented on Jul 8, 2016

    @Yukaii
    Contributor

    vimStyle works with Chinese

    VSC: 1.3.0
    OS: Mac OS X El Capitan

    Tested with Default Zhuyin IM & Squirrel IM

  5. rebornix commented on Jul 8, 2016

    @rebornix
    Contributor

    Yukai Huang (@Yukaii) are you saying Chinese works perfectly using vimStyle even with steps I mentioned above? Not sure if I set up wrong things, but I just installed latest version of vimStyle and tried to type 安 in normal mode, and the vim mode breaks.

  6. alexdima commented on Jul 8, 2016

    @alexdima
    Member

    Bomin Zhang (@localvar) Peng Lyu (@rebornix) I am sorry my VIM sample contained a typo that was causing IME to fail when in insert/append mode:

    See alexdima/vscode-vim@708d4c0

    After that change here is IME in insert mode with my VIM sample:
    vim

    Please note that his works by overwriting the built-in command replacePreviousChar and then delegating back to it as needed. See here

  7. alexdima commented on Jul 8, 2016

    @alexdima
    Member

    Please also note that my sample does not support IME building in normal mode because I am lazy and didn't do it, but not because it could not be possible.

  8. alexdima commented on Jul 8, 2016

    @alexdima
    Member

    Also, possible causes for different behaviour in 1.2.1 could be the PR #5615 -- but IMHO the PR is quite good.

  9. Yukaii commented on Jul 8, 2016

    @Yukaii
    Contributor

    Peng Lyu (@rebornix) you're right, I found Pinyin IM breaks normal mode as you described, Zhuyin IM also has some problems:

    edc97645-c6a2-4fa1-b3e2-dc06f8ad2b43-69456-00017ae0ba8a6e64

    I input "可動" these two word in normal mode and it insert correctly, but when I only type one Zhuyin phonetic character "ㄎ", and press enter, it replace first word "可".

  10. rebornix commented on Jul 10, 2016

    @rebornix
    Contributor

    alexandrudima oh man, you helped all Chinese Vim users out. replacePreviousChar is exactly what we need to handle CJK IME without breaking the Vim Mode.

  11. added
    *question
    on Jul 11, 2016
  12. rebornix commented on Jul 12, 2016

    @rebornix
    Contributor

    alexandrudima played with this API and I found that current information is not enough yet. A really simple example:

    First, below is what will happen when we use Vim with English IME

    1. Open a file
    2. Use English IME
    3. Type a
    4. The Vim mode should be switched to Insert Mode immediately. It's not related to any key strokes after.

    Then use Chinese IME

    1. Open a file
    2. Use Chinese IME
    3. Type a
    4. Our extension (VSCodeVim or alexandrudima 's Vim)'s type command handler will be invoked, and args: {text: 'a'} is passed to it. At the same time, replacePreviousChar is still not invoked.

    Here comes the problem, since we are using Chinese IME, this a might be replaced by a Chinese character later. But if we are using English IME, we should translate this a to Switch Mode to Insert Mode. In type command handler, we have no idea about the IME info so we don't know how to handle this a correctly.

    Another funny example with Chinese IME is

    1. Open a file and the Vim Mode is Normal
    2. Use Chinese IME
    3. Type an
    4. A popup window shows up and provides several possible Chinese characters we want to type in.

    If we type 1, Chinese IME will pick up the first Chinese character listed in the popup. And we will get a replacePreviousChar event, the args passed in is {text: '安', replaceCharCnt: '2'}. However, if we press Enter key, we will get a replacePreviousChar with {text: 'an', replaceCharCnt: '2'} . The expected way of handing this an in Vim is

    1. Switch to Insert Mode (because the first char is a)
    2. Insert n.

    You may already see the problem, when we get the replacePreviousChar event with arguments {text: 'an', replaceCharCnt: '2'}, we have no idea that whether we should replace previous characters with an or translating them to switch to Insert Mode then insert 'n'. Again, that's because we are lack of the information of IME.

    Personally I think it's not a good idea to detect IME info ourselves because we will end up moving the same logic of VS Code to the extension.

  13. alexdima commented on Jul 12, 2016

    @alexdima
    Member

    I will investigate further in our code-base, but beware that we don't have any input building (IME) logic either, Chrome does that.

    We take the "lower-level" events:

    • input
    • compositionstart
    • compositionupdate
    • compositionend

    We then do quite some computation to eliminate the text we have previously placed in the <textarea> for screen readers and to accommodate different browsers and then we deduce what was the diff (what was actually typed). https://github.com/Microsoft/vscode/blob/master/src/vs/editor/common/controller/textAreaHandler.ts#L114

    So far I have found that these two primitives: type and replacePreviousChar were sufficient, but I understand your problem too, especially in normal mode, where the receival of type: a could be a part of building a complex Chinese word or it could be the actual typed a. And once you've made a decision to go into append mode, replacePreviousChar is not really useful.

    I will investigate if we can enrich type and replacePreviousChar, otherwise we might end up exposing something different to help in the normal mode case.

  14. added
    feature-request
    on Jul 15, 2016
  15. alexdima commented on Jul 15, 2016

    @alexdima
    Member

    Here is an example how to use the new compositionStart and compositionEnd:

    alexdima/vscode-vim@2c1ccd7

    The idea is you can overwrite (similar to type and replacePreviousChar) two more -- compositionStart and compositionEnd. These two new ones should help in distinguishing the composition case vs non-composition case.

  16. locked and limited conversation to collaborators on Nov 18, 2017
  17. added a commit that references this issue on Sep 6, 2026
    4f9b0f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*questionVIMfeature-request

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions