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
}
}
Add the following to your plugin configuration.
This will switch to your default input method (e.g., English) when leaving insert mode.
You can set enabled = true
for any OS you use, and adjust default_im
or commands as needed for each environment.
require("im-switch").setup({
windows = {
enabled = true, -- Set to true if you are on Windows/WSL2
},
macos = {
enabled = true, -- Set to true if you are on macOS
default_im = "com.apple.keylayout.ABC", -- or your preferred input method
},
linux = {
enabled = true, -- Set to true if you are on Linux
default_im = "keyboard-us", -- or your preferred input method
get_im_command = { "fcitx5-remote", "-n" }, -- { "ibus", "engine" }
set_im_command = { "fcitx5-remote", "-s" }, -- { "ibus", "engine" }
},
})
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 downloaded using curl
and used automatically.
Warning
Pre-built binaries are available only for:
OS | Architecture |
---|---|
Windows | x86_64 |
macOS | aarch64, x86_64 |
If you need a different version, make sure cargo is installedβthen the plugin will automatically build the executable during installation.
Note
The im-switch
executable will also be rebuilt or updated automatically whenever you update this plugin.
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 = {},
},
}
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" },
},
Run :checkhealth im-switch
if you run into any issues.
This project is licensed under the MIT License - see the LICENSE file for details.