Skip to content

feat: include the ModeChanged event for more flexibility#19

Open
koiking129 wants to merge 2 commits into
keaising:masterfrom
koiking129:feat
Open

feat: include the ModeChanged event for more flexibility#19
koiking129 wants to merge 2 commits into
keaising:masterfrom
koiking129:feat

Conversation

@koiking129

Copy link
Copy Markdown

I have been using this plugin for a while now, and enjoying the convenience of automatically switching IM, thanks for your work.

However, some specific needs cannot be met:

  1. Restoring the default IM on CmdlineLeave is valuable, because we may search for some text in the command line. But, in most cases, we just want to execute some commands (e.g. :w), and only the default IM will be used. So, we may not expect the default IM to override the previous IM.
  2. There is a wired (I'm a Vim newbie) behavior in Neovim: the CmdlineEnter (pattern i:c) and CmdlineLeave (pattern c:i) events will be triggered when I type the Enter key in the insert mode, which may cause unexpected IM state switching if CmdlineLeave is included in set_default_events.

Workaround:

The ModeChanged event supports the pattern match to identify events precisely:

  1. Saving the IM state only on the limited pattern (e.g. i:n, R:n), which could be configured in save_state_patterns.
  2. Don't switch the IM state on the specified pattern (e.g. i:c, c:i), which could be configured in exclude_patterns.

这个插件非常棒,非常方便,感谢作者的积极维护。

用一段时间后,发现了一些问题:

  1. 退出命令行模式时回到英文输入法是很有必要的,因为偶尔搜索文本会切换输入法,但是,大多数时候只是进入命令行模式保存文件,这就不会切换输入法。所以,我不希望退出命令行的时候覆盖上一次保存的输入法。
  2. 我的Neovim有一个奇怪的行为(也可是我不懂):在插入模式下敲回车换行会触发CmdlineEnteri:c模式)和CmdlineLeavec:i模式)事件,如果在set_default_events中配置了CmdlineLeave就会自动切换为英文输入法。

解决方案:

ModeChanged支持使用模式匹配来精确识别事件:

  1. 可以限定几个需要保存输入法的事件模式,其他事件模式都不保存输入法;在save_state_patterns里面配置
  2. 可以指定一些事件模式不要切换输入法;在exclude_patterns里面配置

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants