/cjk-word-handler

Visual Studio Code extension to improve CJK (Chinese, Japanese, Korean) word handling.

Primary LanguageTypeScriptzlib LicenseZlib

CJK Word Handler

zlib license

Better cursor movement in CJK language text for VS Code.

This is an extension directly modified from another extension Japanese Word Handler developed by sgryjp. Node segment is used for Chinese word segmentation.

Usage

VSCode partitions English text into words by spaces and English punctuations. Then users can move the cursor by words instead of by characters when ctrl is pressed. However, because this partitioning strategy does not work correctly for CJK language text, this feature behaves badly with these languages. For example, ctrl + Right will make the cursor move directly to the end of line in Chinese environment. This extension aims to solve this problem.

Just install the extension. Doing so changes the action for the keybindings below (on macOS, use ⌥Option instead of Ctrl):

  • Ctrl+Right
  • Ctrl+Left
  • Ctrl+Shift+Right
  • Ctrl+Shift+Left
  • Ctrl+Delete
  • Ctrl+Backspace

Although not visible in command platte, these actions are implemented as commands so that you can reassign any key combinations to them.

A configuration is provided to customize the partitioning strategy. By default we partition Chinese into words via node segment. We can adjust the strategy by changing cjkWordHandler.chinesePartitioningRule to "By characters" or "By sentences".

Known limitations

Due to the limitation of node segment, there will be a delay of one second or so at the first time using this extension.

As of VSCode 1.41.0, extension cannot override word related actions below:

  • Word selection on double click
  • Automatic highlight of a word at where the cursor is
  • 'Match Whole Word' option of text search

Issue report

Please visit the project's GitHub page and report it. Contributions are welcome.

Enjoy!