Skip to content

Conversation

@u-tung
Copy link

@u-tung u-tung commented Dec 8, 2025

What this PR does / why we need it:

CJK languages have a character count that far exceeds the number of keys on a keyboard, requiring multiple keystrokes to compose a single character. This makes it impossible to use a simple langmap to control Vim's operations. Traditionally, the autoSwitchInputMethod approach is used to automatically switch input methods, but this method has some drawbacks:

  • Unable to maintain consistent input method after switching between insert/normal mode
  • Requires additional dependencies (im-select)
  • Needs system permissions
  • Perceptible delay when switching from insert mode to normal mode (based on my own experience)

I added an option vim.mapIMEComposition.enable (and the corresponding vim.mapIMEComposition.map) to enable mapping IME composition input to Latin characters.
This allows users to control VIM's operations without switching CJK input methods.
For me, a consistent input method across various modes has greatly enhanced my experience of using vscodevim and Chinese input.

Implementation Details

To achieve this functionality, each character of the composition needs to be processed as a separate input, which requires the ability to interrupt the IME's composition state.

VSCode does not provide such functionality, so I used some clever implementation methods to interrupt the IME's composition state by switching the current focus target.

example:

await vscode.commands.executeCommand('workbench.action.focusTitleBar');
await vscode.commands.executeCommand('workbench.action.focusPreviousGroup');

This is not an ideal solution, but it works fine most of the time, with some issues only in extreme cases (when I purposely tap the keyboard quickly in succession).

Additional modifications

I removed some unnecessary async prefixes from functions, slightly reducing the occurrence rate of input issues.

Configuration Example

// Map the zhuyin input method of macOS to Latin characters.
"vim.mapIMEComposition.enable": true,
"vim.mapIMEComposition.map": {
    "ㄇ": "a",
    "ㄖ": "b",
    "ㄏ": "c",
    "ㄎ": "d",
    "ㄍ": "e",
    "ㄑ": "f",
    "ㄕ": "g",
    "ㄘ": "h",
    "ㄛ": "i",
    "ㄨ": "j",
    "ㄜ": "k",
    "ㄠ": "l",
    "ㄩ": "m",
    "ㄙ": "n",
    "ㄟ": "o",
    "ㄣ": "p",
    "ㄆ": "q",
    "ㄐ": "r",
    "ㄋ": "s",
    "ㄔ": "t",
    "ㄧ": "u",
    "ㄒ": "v",
    "ㄊ": "w",
    "ㄌ": "x",
    "ㄗ": "y",
    "ㄈ": "z",
    "A": "A",
    "B": "B",
    "C": "C",
    "D": "D",
    "E": "E",
    "F": "F",
    "G": "G",
    "H": "H",
    "I": "I",
    "J": "J",
    "K": "K",
    "L": "L",
    "M": "M",
    "N": "N",
    "O": "O",
    "P": "P",
    "Q": "Q",
    "R": "R",
    "S": "S",
    "T": "T",
    "U": "U",
    "V": "V",
    "W": "W",
    "X": "X",
    "Y": "Y",
    "Z": "Z",
    "ㄅ": "1",
    "ㄉ": "2",
    "ˇ": "3",
    "ˋ": "4",
    "ㄓ": "5",
    "ˊ": "6",
    "˙": "7",
    "ㄚ": "8",
    "ㄞ": "9",
    "ㄢ": "0",
    "!": "!",
    "@": "@",
    "#": "#",
    "$": "$",
    "%": "%",
    "^": "^",
    "&": "&",
    "*": "*",
    "(": "(",
    ")": ")",
    "_": "_",
    "+": "+",
    "「": "[",
    "」": "]",
    "·": "`",
    "ㄦ": "-",
    "=": "=",
    "、": "\\",
    "ㄤ": ";",
    "‘": "'",
    "ㄝ": ",",
    "ㄡ": ".",
    "ㄥ": "/",
    "『": "{",
    "』": "}",
    "|": "|",
    ":": ":",
    "“": "\"",
    ",": "<",
    "。": ">",
    "?": "?",
    "j": "∆",
    "k": "˚"
}

Relative Issues

#9858

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant