Giter Site home page Giter Site logo

vim-im-select's Introduction

vim-im-select

Improve Vim/Neovim experience with input methods.

Basically, this plugin does these things:

  • Switch to the default IM of your choice on InsertLeave
  • Switch back to your previous IM on InsertEnter
  • Switch to the default IM of your choice on FocusGained if you are in normal mode, or do nothing if not
  • Switch back to your 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 your 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 of your choice 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/Vim cannot recognize the terminal code from this plugin, 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. default value is 1.

vim-im-select's People

Contributors

brglng avatar kiyohara avatar ytyubox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vim-im-select's Issues

Need a guide on Windows (10)

Though some say PowerShell has commands to support this, I doubt it can be used by this, so I did not look into them.
A guide on what the IME switching command is and how to configure this at all, would be so helpful.

fcitx5 support

diff --git a/plugin/im_select.vim b/plugin/im_select.vim
index 0b8c522..baa46bc 100644
--- a/plugin/im_select.vim
+++ b/plugin/im_select.vim
@@ -59,6 +59,17 @@ if !exists('g:im_select_get_im_cmd') || !exists('g:ImSelectSetImCmd')
             if !exists('g:im_select_default')
                 let g:im_select_default = '1'
             endif
+        elseif $GTK_IM_MODULE == 'fcitx5' || $QT_IM_MODULE == 'fcitx5'
+            let g:im_select_get_im_cmd = ['fcitx5-remote']
+            let g:ImSelectSetImCmd = {
+              \ key ->
+              \ key == 1 ? ['fcitx5-remote', '-c'] :
+              \ key == 2 ? ['fcitx5-remote', '-o'] :
+              \ execute("throw 'invalid im key'")
+              \ }
+            if !exists('g:im_select_default')
+                let g:im_select_default = '1'
+            endif
         elseif match($XDG_CURRENT_DESKTOP, '\cgnome') >= 0
             if $GTK_IM_MODULE == 'ibus'
                 let g:im_select_get_im_cmd = [
@@ -98,6 +109,17 @@ if !exists('g:im_select_get_im_cmd') || !exists('g:ImSelectSetImCmd')
                 if !exists('g:im_select_default')
                     let g:im_select_default = '1'
                 endif
+            elseif $GTK_IM_MODULE == 'fcitx5' || $QT_IM_MODULE == 'fcitx5'
+                let g:im_select_get_im_cmd = ['fcitx5-remote']
+                let g:ImSelectSetImCmd = {
+                            \ key ->
+                            \ key == 1 ? ['fcitx5-remote', '-c'] :
+                            \ key == 2 ? ['fcitx5-remote', '-o'] :
+                            \ execute("throw 'invalid im key'")
+                            \ }
+                if !exists('g:im_select_default')
+                    let g:im_select_default = '1'
+                endif
             endif
         endif
     endif

Support command line mode and search mode

On CmdlineEnter, switch to the same input method as insert mode or the previous input method before leaving command line / search mode. (As if imsearch is -1, 1 or 2)

On CmdlineLeave, switch to the default input method.

Support `f F t T r` commands

gVim 对 f F t T r 等命令的支持非常得人性化,中文输入非常友好。按下 f 等命令后,输入法状态和插入模式的相同。结束命令回到普通模式,自动切换到英文输入法。

我尝试了一下,好像只有改写这些命令才能实现类似 gVim 的行为。vim-im-select 能不能支持这些命令?下面是我做的尝试:

nnoremap <silent> f <Cmd>call FindChar('f')<Cr>

function! FindChar(motion) abort
    " 切换到和插入模式相同的输入法状态

    " 调用原本的 f 命令
    let l:c = getcharstr()
    execute('normal! ' . a:motion . l:c)

    " 保存输入法状态,并切换回默认输入法
endfunction

fcitx5 命令检测有问题

我在 Debian 12 中使用 fcitx,发现新版本的 fcitx5 对环境变量的设置已经变成 fcitx 了,所以最好不要用环境变量判断 fcitx/fcitx5,而应该使用其他方式。

图片

Optimize startup time?

Env

  • OS : macOS 10.15
  • Vim: 8.0.200
  • IME: macOS default
    • ABC
    • Pinyin - Simplified

Startup time profile

====================================
Top 10 plugins slowing vim's startup
====================================
1	 26.123   vim-im-select
2	  5.545   coc.nvim
3	  2.976   emmet-vim
4	  2.145   vim-devicons
5	  1.845   vim-gruvbox8
6	  1.739   vim-sneak
7	  1.331   lightline.vim
8	  0.993   fzf.vim
9	  0.930   vim-table-mode
10	  0.850   fzf
====================================

Generated by hyiltiz/vim-plugins-profile

Problem

I like vim-im-select. It improves my typing experience greatly. But it takes a relatively long time to start up. Is there any way to cut down the startup time?

My neovim will not switch automatically

The plugin status is normal and I have executed "ImSelectEnable", but pressing the back key for Chinese input does not switch back to English
os:ubunut22.04
editor:neovim8.1
ibus
GTK_IM_MODULE=ibus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.