Japanese Word Navigation
日本語
Makes word-based cursor movement, selection, and deletion (Ctrl+←/→ and so on) split words where the Japanese character type changes.
Rewritten from scratch based on the behavior and test cases of sgryjp/japanese-word-handler by Suguru Yamamoto (zlib License). This is a modified version, not the original extension published by its author.
Behavior
Characters are classified into the following types, and a word boundary is placed wherever the type changes.
| Type |
Examples |
| Alphanumeric |
a–z, 0–9, _, full-width alphanumerics, Latin letters |
| Hiragana |
あ–ん |
| Katakana |
ア–ン, ー, half-width katakana |
| Symbol |
ASCII symbols such as !–/, 、, 。, 「, ・, etc. |
| Separator |
Characters in the editor.wordSeparators setting |
| Other |
Kanji, 々, emoji, etc. |
| Whitespace |
Space, tab, full-width space |
| Key (Windows/Linux) |
Key (macOS) |
Action |
| Ctrl+← |
Alt+← |
Move to the start of the previous word |
| Ctrl+→ |
Alt+→ |
Move to the end of the next word |
| Ctrl+Shift+← / → |
Alt+Shift+← / → |
Select to the same position |
| Ctrl+Backspace |
Alt+Backspace |
Delete to the start of the previous word |
| Ctrl+Delete |
Alt+Delete |
Delete to the end of the next word |
Commands without default keys (japaneseWordNavigation.cursorWordEndLeft, cursorWordStartRight, and their select/delete variants) can be assigned in Keyboard Shortcuts.
Command names are shown in English or Japanese according to the VS Code display language.
Changes from the original extension
- Instead of querying VS Code for each character, it reads the line text once and classifies it (fixes slowness on long lines).
- Fixed a bug where Ctrl+Backspace at the start of a line deleted too much, skipping over empty lines.
- When there is a selection, deletion removes only the selection (same as VS Code's default).
- Overlapping deletion ranges with multiple cursors no longer cause an error.
- Command IDs were renamed to
japaneseWordNavigation.*. The old command names (extension.*) and the build for VS Code for the Web were removed.
It uses the same keys as the original extension, so if both are installed it is undefined which one receives the key. Uninstall the original extension first.
日本語
Ctrl+←/→ などの単語単位のカーソル移動・選択・削除を、日本語の文字種の境目で区切るようにする拡張機能。
Suguru Yamamoto 氏の sgryjp/japanese-word-handler(zlib License)の動作仕様とテストケースをもとに、コードを一から書き直したもの。元の作者が公開している拡張そのものではなく、それを改変したバージョンである。
動作
文字を次の種類に分け、種類が変わる位置を単語の境目とする。
| 文字種 |
例 |
| 英数字 |
a〜z、0〜9、_、全角英数字、ラテン文字 |
| ひらがな |
あ〜ん |
| カタカナ |
ア〜ン、ー、半角カタカナ |
| 記号 |
!〜/ などの ASCII 記号、、、。、「、・ など |
| 区切り文字 |
設定 editor.wordSeparators に含まれる文字 |
| その他 |
漢字、々、絵文字など |
| 空白 |
スペース、タブ、全角スペース |
| キー(Windows/Linux) |
キー(macOS) |
動作 |
| Ctrl+← |
Alt+← |
前の単語の先頭へ移動 |
| Ctrl+→ |
Alt+→ |
次の単語の末尾へ移動 |
| Ctrl+Shift+← / → |
Alt+Shift+← / → |
上と同じ位置まで選択 |
| Ctrl+Backspace |
Alt+Backspace |
前の単語の先頭まで削除 |
| Ctrl+Delete |
Alt+Delete |
次の単語の末尾まで削除 |
キーが割り当てられていないコマンド(japaneseWordNavigation.cursorWordEndLeft、cursorWordStartRight とその選択・削除版)も、キーボードショートカットの設定から割り当てられる。
コマンド名は、VS Code の表示言語に合わせて日本語か英語で表示する。
元の拡張からの変更点
- 文字を 1 文字ずつ VS Code に問い合わせるのをやめ、行の文字列を 1 回取り出して判定するようにした(長い行での遅さの解消)。
- 行頭で Ctrl+Backspace を押したとき、空行を飛び越えて消しすぎる不具合を直した。
- 選択範囲があるときの削除は、その選択範囲だけを消す(VS Code 標準と同じ)。
- 複数カーソルの削除範囲が重なってもエラーにならない。
- コマンド ID を
japaneseWordNavigation.* に改めた。旧コマンド名(extension.*)とブラウザ版 VS Code 向けのビルドは無くした。
元の拡張と同じキーを割り当てているため、両方を入れるとキー操作がどちらに渡るか定まらない。元の拡張はアンインストールしておくこと。
開発
npm install # typescript と @types/vscode だけ
npm test # ビルドして単語境界のテストを実行(node:test)
npm run package # .vsix を作成(vsce は npx でその都度取得)
npm run icon # images/icon.svg を images/icon.png(256×256)に書き出す(sharp-cli は npx でその都度取得)
npm run publish:marketplace # VS Code Marketplace に公開(事前に vsce login ExpressionInc)