im-switch.nvim
is a Neovim plugin that automatically switches the input method (IM) based on specific events.
This is useful for users who frequently switch between different input methods (e.g., English and Japanese) while coding.
- π Switch input method according to Neovim events
- π¦ No need to install other tools to switch input method like im-select
- π₯οΈ Works on Windows/macOS/Linux
OS | Requirements |
---|---|
All OS | Neovim >= 0.10.0 plenary.nvim |
Windows/macOS | cargo >= 1.75.0 (optional) |
Linux | An input method framework (e.g., fcitx5 , ibus ) |
Install the plugin with your preferred package manager.
{ "nvim-lua/plenary.nvim", lazy = true }, -- plenary.nvim is required
{
"drop-stones/im-switch.nvim",
event = "VeryLazy",
opts = {
-- your configurations
}
}
Neovim itself cannot switch the input method directly.
Instead, this plugin invokes an external executable to handle the switching process.
On Windows/macOS, a Rust-based command-line utility, im-switch
, is required.
If cargo
is installed, im_switch
will be built automatically during plugin installation.
Otherwise, a pre-built binary will be used.
Warning
Pre-built binaries are available only for:
OS | Architecture |
---|---|
Windows | x86_64 |
macOS | arm64 |
If you need a different version, install cargo and build it manually.
On Linux, input method switching is handled through an input method framework (e.g., fcitx5
, ibus
).
Make sure your system has an appropriate input method framework installed and configured.
You can customize im-switch behavior with the following options.
Expand to see the list of all the default options below.
Default Options
{
-- Events that set the default input method.
default_im_events = { "VimEnter", "FocusGained", "InsertLeave", "CmdlineLeave" },
-- Events that save the current input method.
save_im_state_events = { "InsertLeavePre" },
-- Events that restore the previously saved input method.
restore_im_events = { "InsertEnter" },
-- Windows settings
windows = {
-- Enable or disable the plugin on Windows/WSL2.
enabled = false,
};
-- macOS settings
macos = {
-- Enable or disable the plugin on macOS.
enabled = false,
-- The input method set when `default_im_events` is triggered.
default_im = "",
},
-- Linux settings
linux = {
-- Enable or disable the plugin on Linux.
enabled = false,
-- The input method set when `default_im_events` is triggered.
default_im = "",
-- The command used to get the current input method when `save_im_state_events` is triggered.
get_im_command = {},
-- The command used to set the input method when `default_im_events` or `restore_im_events` is triggered.
set_im_command = {},
},
}
Important
If you encounter any issues, run :checkhealth im-switch
to diagnose problems.
Events that set the default input method.
default_im_events = { "VimEnter", "FocusGained", "InsertLeave", "CmdlineLeave" }
Events that save the current input method.
The saved input method is restored when restore_im_events
is triggered.
save_im_state_events = { "InsertLeavePre" },
Events that restore the previously saved input method.
restore_im_events = { "InsertEnter" },
Tip
Always Switch to Default IM on Mode Change
To always switch to the default IM instead of restoring the previous one:
save_im_state_events = {},
restore_im_events = {},
Enable or disable the plugin on Windows/WSL2.
windows = {
enabled = false,
},
Enable or disable the plugin on macOS.
macos = {
enabled = true,
},
The input method set when default_im_events
is triggered.
macos = {
default_im = "com.apple.keylayout.ABC",
},
Enable or disable the plugin on Linux.
linux = {
enabled = true,
},
The input method set when default_im_events
is triggered.
linux = {
default_im = "keyboard-us",
},
The command used to get the current input method when save_im_state_events
is triggered.
linux = {
get_im_command = { "fcitx5-remote", "-n" },
},
The command used to set the input method when default_im_events
or restore_im_events
is triggered.
linux = {
set_im_command = { "fcitx5-remote", "-s" },
},
This project is licensed under the MIT License - see the LICENSE file for details.