nihongo.nvim
LiveOpen source · MIT licenceJapanese-aware motions, IME switching, and romaji search for Neovim, in pure Lua.
Overview
Japanese text has no spaces, so Neovim's w and b treat a whole sentence as one word. nihongo.nvim replaces them with motions that segment Japanese by character class and particle boundaries, so w steps noun by noun the way it does in English. It also watches where the cursor sits. Entering insert mode inside a comment, string, or markdown file switches the IME to Japanese, and leaving it snaps back to ASCII, per buffer. A romaji to kana layer turns a query like kensaku into a pattern that matches 検索. The segmenter itself is zero dependency Lua.
Highlights
- Word segmentation from character class transitions and a particle table, so kanji plus okurigana stays one word but は, が, を start a new one
- Falls straight through to native w and b on lines with no Japanese, so English editing is untouched
- Context-aware IME switching driven by treesitter node type, with a syntax group fallback for buffers treesitter does not parse
- Per buffer IME memory: code and comments each remember their own last state, and the buffer's default is inferred by scanning its first 100 lines for Japanese
- Romaji to hiragana and katakana conversion, including double consonants (gakkou to がっこう), built into a search pattern that matches all three scripts at once
- Supports fcitx5, ibus, im-select, and arbitrary custom switch commands