Skip to content

Latest commit

 

History

History
136 lines (91 loc) · 3.74 KB

README.md

File metadata and controls

136 lines (91 loc) · 3.74 KB

vim-im-select

Improve Vim/Neovim experience with input methods.

Basically, this plugin does these things:

  • Switch to the "default IM" on InsertLeave
  • Switch back to the previous IM on InsertEnter
  • Switch to the "default IM" on FocusGained if you are in normal mode, or do nothing if not
  • Switch back to the previous IM on FocusLost if you are in normal mode, or do nothing if not
  • If you are using a GUI (e.g., GVim), switch back to the previous IM before exiting Vim if you are in normal mode, or do nothing if you are in insert mode. If you are under a terminal, switch to the "default IM" before exiting Vim.

Requirements

Neovim or Vim with +job is required.

This plugin works out of the box on Linux with iBus or Fcitx.

On macOS or Windows, im-select must be installed.

Tmux

tmux-plugins/vim-tmux-focus-events is recommended if you are using Tmux. This plugin provides FocusGained and FocusLost events for (Neo)Vim under Tmux. (NOTE: It is reported that this plugin does not work well with Vim, however it works well with Neovim.)

Commands

ImSelectEnable

Enable this plugin if not enabled.

ImSelectDisable

Disable this plugin.

Options

g:im_select_get_im_cmd

This variable can be set to a list or a string of the command for getting the current IM key.

e.g.

let g:im_select_get_im_cmd = ['im-select']

g:ImSelectSetImCmd

This variable must be a Funcref who takes the key as argument and returns the whole command line.

e.g.

let g:ImSelectSetImCmd = {key -> ['im-select', key]}

g:ImSelectGetImCallback

This variable must be a Funcref, which is called after the get_im command is exited, returning the current IM key.

e.g.

function! GetImCallback(exit_code, stdout, stderr) abort
    return a:stdout
endfunction
let g:ImSelectGetImCallback = function('GetImCallback')

g:im_select_default

This variable can be set to your own default IM key.

e.g.

let g:im_select_default = 'com.apple.keylayout.ABC'   " The default value on macOS
let g:im_select_default = '1033'                      " The default value on Windows

You can get your current IM key by im-select.

$ im-select
com.apple.keylayout.ABC

You are likely to get com.apple.keylayout.Dvorak if you use Dvorak keyboard layout on macOS.

g:im_select_command

This variable can be set to the im-select program path of your own (only useful on macOS and Windows).

g:im_select_switch_timeout

The timeout during which events are not responded, in milliseconds.

Some IM switching commands steals focus, e.g., the gdbus program on GNOME desktop. This will trigger FocusLost and FocusGained events, which causes problems. This option setups the timeout after the IM is switched. During the timeout, events are not responded. The default value is 50.

g:im_select_enable_focus_events

Whether or not to enable FocusLost and FocusGained events. If your desktop already switches input methods among different windows/applications (e.g., this is the default setting on KDE), you may want to set this option to 0. The default value is 1.

g:im_select_enable_for_gvim

The plugin is disabled on GVim for Windows or MacVim, as GVim for Windows and MacVim already supports IM auto-switching. Set this variable to 1 if you want to enable anyway.

g:im_select_enable_cmd_line

Set this variable to 0 if you want disable IM switching in the command-line mode. This setting is useful for users who wish to use a different input method (specifically for English characters) in the command-line mode, as opposed to the main text. The default value is 1.