8000 GitHub - drop-stones/im-switch.nvim: Neovim plugin to switch IM automatically.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

drop-stones/im-switch.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

im-switch.nvim

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.

✨ Features

  • πŸ”„ 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

⚑️ Requirements

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)

πŸ“¦ Installation

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
  }
}

πŸ–₯️ Executable for Input Method Switching

Neovim itself cannot switch the input method directly.
Instead, this plugin invokes an external executable to handle the switching process.

🌐 Windows/macOS

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.

🐧 Linux

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.

βš™οΈ Configuration

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.

πŸ”§ General Configuration

default_im_events

Events that set the default input method.

default_im_events = { "VimEnter", "FocusGained", "InsertLeave", "CmdlineLeave" }

save_im_state_events

Events that save the current input method.
The saved input method is restored when restore_im_events is triggered.

save_im_state_events = { "InsertLeavePre" },

restore_im_events

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 = {},

πŸͺŸ Windows Configuration

windows.enabled

Enable or disable the plugin on Windows/WSL2.

windows = {
  enabled = false,
},

🍎 macOS Configuration

macos.enabled

Enable or disable the plugin on macOS.

macos = {
  enabled = true,
},

macos.default_im

The input method set when default_im_events is triggered.

macos = {
  default_im = "com.apple.keylayout.ABC",
},

🐧 Linux Configuration

linux.enabled

Enable or disable the plugin on Linux.

linux = {
  enabled = true,
},

linux.default_im

The input method set when default_im_events is triggered.

linux = {
  default_im = "keyboard-us",
},

linux.get_im_command

The command used to get the current input method when save_im_state_events is triggered.

linux = {
  get_im_command = { "fcitx5-remote", "-n" },
},

linux.set_im_command

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" },
},

License

This project is licensed under the MIT License - see the LICENSE file for details.

0