Giter Site home page Giter Site logo

smartim's Introduction

What is this?

SmartIM is a plugin to make vim stand well with input methods. It switches the input method to the default keyboard (usually English) when leaving insert mode and switches back when you enter insert mode again. It consists of 2 tiny programs:

  • im-select: a command-line utility to get/set active input method
  • smartim.vim: a vim plugin to do automatic input method switch, using im-select

It is Mac-only for now.

Installation

Vundle

  1. Add this line to your ~/.vimrc file: Plugin 'ybian/smartim'
  2. Open vim and run :PluginInstall

Pathogen

  1. cd ~/.vim/bundle
  2. git clone [email protected]:ybian/smartim.git

Others

  1. Clone this repository to your local disk
  2. Copy im-select and smartim.vim (both are under plugin directory) to your vim plugin directory (usually .vim/plugins)

Then, enjoy the convenience!

FAQ

Why is it Mac-only?

Because the command-line utility im-select uses Mac specific APIs. It should be easy to develop equivalents for other platforms but I just don't have the time to do so.

Can I use im-select as a standalone utility?

Sure. The usage is very simple: invoke it with no argument to get the ID string of current active input method; invoke it with an ID string to set current input method.

$ im-select
com.apple.keylayout.US # print the ID string of your active input method
$ im-select com.apple.keylayout.US # change your active input method

What should I do if my default keyboard is not US English?

SmartIM assumes your default keyboard is US English (com.apple.keylayout.US). If you want to change this, please add the following line to your .vimrc:

let g:smartim_default = '<your_default_keyboard_id>'

Replace <your_default_keyboard_id> with the ID string of your input method (which can be get via im-select)

Somehow I want to disable this plugin

For example, some people reported that it is slow while editing with vim-multiple-cursors, to fix this, put this in .vimrc:

function! Multiple_cursors_before()
  let g:smartim_disable = 1
endfunction
function! Multiple_cursors_after()
  unlet g:smartim_disable
endfunction

I have other problems to debug...

Follow the following steps:

  1. Run vim with vim --cmd 'let g:smartim_debug=1'
  2. Enter and leave insert mode for a couple of times to reproduce your problem; then exit vim.
  3. Open an issue on github and attach the content of ~/vim_smartim_debug_output

smartim's People

Contributors

carloswong avatar chaoyuelee avatar chemzqm avatar kaidiren avatar su27 avatar ybian 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  avatar

smartim's Issues

Not working in terminal Vim

Thanks for developing the plugin!

But it works only in MacVim (GUI Vim), does not work in Vim at terminal (Using iTerm2).

Any ways to use smartim in terminal Vim? Or required to config iTerm2...

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12
BuildVersion:   16A323
$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct 12 2016 20:20:27)
MacOS X (unix) version
Included patches: 1-27
Compiled by Homebrew
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl             +find_in_path    -mouse_sysmouse  -tag_any_white
+arabic          +float           +mouse_urxvt     +tcl
+autocmd         +folding         +mouse_xterm     +termguicolors
+balloon_eval    -footer          +multi_byte      +terminfo
+browse          +fork()          +multi_lang      +termresponse
++builtin_terms  +fullscreen      -mzscheme        +textobjects
+byte_offset     -gettext         +netbeans_intg   +timers
+channel         -hangul_input    +num64           +title
+cindent         +iconv           +odbeditor       +toolbar
+clientserver    +insert_expand   +packages        +transparency
+clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        +perl            +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       -python          +vreplace
+cscope          +lispindent      +python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con_gui  +lua             +rightleft       +writebackup
+diff            +menu            +ruby            -X11
+digraphs        +mksession       +scrollbind      -xfontset
+dnd             +modify_fname    +signs           +xim
-ebcdic          +mouse           +smartindent     -xpm
+emacs_tags      +mouseshape      +startuptime     -xsmp
+eval            +mouse_dec       +statusline      -xterm_clipboard
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax
+farsi           +mouse_netterm   +tag_binary
+file_in_path    +mouse_sgr       +tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -L/usr/local/lib -L. -L/usr/local/lib  -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework Cocoa  -L/usr/local/opt/lua/lib -llua -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl  -L/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/config-3.5m -lpython3.5m -framework CoreFoundation -F/System/Library/Frameworks -framework Tcl -framework CoreFoundation -framework Ruby

使用 Ctrl-C 来切换到 normal mode 并不会切换到输入法

开发者大大!
你好!
我使用的是 macbook air M1, macOS 12.0.1, neovim 0.6.1,在使用这个插件的时候,<ESC>Ctrl-[ 都能成功的退出插入模式并切换到英文输入法。但是 Ctrl-C 并不行。

此外我还使用 imap jk <Esc> 来使得 jk 映射为 ESC,我在 mac系统的偏好设置-键盘-文本里添加了一条文本替换 Repalce jk With jk,这样我在中文输入法状态下输入 jk + 空格,就可以切换到 normal mode, 并且会自动切换输入法,这挺神奇的。

以下是 debug 文件的报告

2022-01-26_02:48:41] - Debug Start
[2022-01-26_02:48:41] g:smartim_loaded = 1
[2022-01-26_02:48:41] g:smartim_default = com.apple.keylayout.US
[2022-01-26_02:48:41] g:smartim_disable = 0
[2022-01-26_02:48:41] g:smartim_debug = 1
[2022-01-26_02:48:41] s:imselect_path = /Users/northyear/.local/share/nvim/plugged/smartim/plugin/im-select 
[2022-01-26_02:48:43] >>> Smartim_SelectSaved
[2022-01-26_02:48:43] <<< Smartim_SelectSaved returned
[2022-01-26_02:51:50] >>> Smartim_SelectDefault
[2022-01-26_02:51:51] b:saved_im = com.apple.keylayout.US�
[2022-01-26_02:51:51] <<< Smartim_SelectDefault returned 0

update:

目前发现使用 vimR, iterm2, 系统自带terminal 来打开 neovim, C-c 切换输入法都有问题。 但是 VSCode-neovim 却没有问题,但是 vscode-neovim 却不能在中文输入法下用 jk + 空格进入 normal mode. (VSCode-Neovim 带来了额外一层的复杂度,我并不奢求大大能够去解决它,这里仅仅是提供一个 data point而已)

使用系统中的 im-select

你好,我注意到这个插件是将 im-select 二进制文件打包进去的,但已经两年没有更新。

是否应该使用系统中的 im-select?作者提供了 brew tap,安装和升级很方便。

或者改为优先使用系统路径中的 im-select,其次调用插件内的 im-select。

Conflict with vim plugin VisIncr

When install both smartim and VisIncr, the running time of VisIncr will be quite long(about 1.5s). If disable smartim temporarily, there won't be such issue.

I would attach the profiling log and reproduce steps if you need them.

Thanks!

Does not work with Sierra?

Hi,

I installed the plugin via Vundle, but not working as expected.

I'm not sure whether MacVim or macOS Sierra causes.

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 20 2016 19:47:58)
MacOS X (unix) version
Included patches: 1-3
Compiled by Homebrew
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl             +find_in_path    -mouse_sysmouse  -tag_any_white
+arabic          +float           +mouse_urxvt     +tcl
+autocmd         +folding         +mouse_xterm     +termguicolors
+balloon_eval    -footer          +multi_byte      +terminfo
+browse          +fork()          +multi_lang      +termresponse
++builtin_terms  +fullscreen      -mzscheme        +textobjects
+byte_offset     -gettext         +netbeans_intg   +timers
+channel         -hangul_input    +num64           +title
+cindent         +iconv           +odbeditor       +toolbar
+clientserver    +insert_expand   +packages        +transparency
+clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        +perl            +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       -python          +vreplace
+cscope          +lispindent      +python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con_gui  +lua             +rightleft       +writebackup
+diff            +menu            +ruby            -X11
+digraphs        +mksession       +scrollbind      -xfontset
+dnd             +modify_fname    +signs           +xim
-ebcdic          +mouse           +smartindent     -xpm
+emacs_tags      +mouseshape      +startuptime     -xsmp
+eval            +mouse_dec       +statusline      -xterm_clipboard
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax          
+farsi           +mouse_netterm   +tag_binary      
+file_in_path    +mouse_sgr       +tag_old_static  
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: clang   -L. -L/usr/local/lib -L. -L/usr/local/lib  -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework Cocoa  -L/usr/local/opt/lua/lib -llua -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl  -L/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/config-3.5m -lpython3.5m -framework CoreFoundation -F/System/Library/Frameworks -framework Tcl -framework CoreFoundation -framework Ruby    

macOS Sierra 10.12 (16A323)

Neovim Exits with Code 134 When Quitting with smartim Plugin Enabled

I've encountered a consistent issue where Neovim exits with a return code of 134 (indicative of an abort signal) when attempting to quit, provided the smartim plugin is enabled. This problem seems to manifest specifically when handling input methods on macOS, potentially related to how the plugin interacts with Neovim's exit sequence.

Environment:
OS: macOS 14.3.1
Neovim Version: 0.9.5
smartim Plugin Version: 1.0.1

The issue does not occur if I disable the following line:
autocmd VimLeavePre * call Smartim_SelectDefault()

插件执行很慢, 有办法改善吗?

表现

每次切换 insert mode/normal mode 都要卡顿 1+ 秒钟

os version

10.13.6 (17G65)

neovim version

NVIM v0.3.1
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GE
NERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20180721-48604-1emkq4l/neovim-0.3.1/build/config -I/tmp/neovim-20180721-48604-1emkq4l/neovim-0.3.1/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/neovim-20180721-48604-1emkq4l/neovim-
0.3.1/build/src/nvim/auto -I/tmp/neovim-20180721-48604-1emkq4l/neovim-0.3.1/build/include
Compiled by [email protected]

Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.3.1/share/nvim"

profile

FUNCTION  Smartim_debug_print()
Called 35 times
Total time:   0.000201
 Self time:   0.000201

count  total (s)   self (s)
   35              0.000112   if g:smartim_debug == 0
   35              0.000035     return
                              endif
                            
                              let l:debug_msg = strftime("[%Y-%m-%d_%H:%M:%S]") . ' ' . a:msg
                              silent call writefile([l:debug_msg], s:smartim_debug_output, "a")


FUNCTION  Smartim_SelectSaved()
Called 6 times
Total time:   0.998683
 Self time:   0.998595

count  total (s)   self (s)
    6   0.000046   0.000030   call Smartim_debug_print('>>> Smartim_SelectSaved')
                            
    6              0.000007   if g:smartim_disable == 1
                                return
                              endif
                            
    6              0.000016   if exists("b:saved_im")
    5              0.998179     silent call system(s:imselect_path . b:saved_im)
    5   0.000253   0.000199     call Smartim_debug_print('b:saved_im = ' . b:saved_im)
    5   0.000049   0.000035     call Smartim_debug_print('<<< Smartim_SelectSaved returned ' . v:shell_error)
    5              0.000006   else
    1   0.000006   0.000004     call Smartim_debug_print('<<< Smartim_SelectSaved returned')
    1              0.000001   endif

FUNCTION  Smartim_SelectDefault()
Called 6 times
Total time:   2.451158
 Self time:   2.451045

count  total (s)   self (s)
    6   0.000072   0.000045   call Smartim_debug_print('>>> Smartim_SelectDefault')
                            
    6              0.000011   if g:smartim_disable == 1
                                return
                              endif
                            
    6              1.240610   silent let b:saved_im = system(s:imselect_path)
    6              1.209991   silent call system(s:imselect_path . g:smartim_default)
                            
    6   0.000295   0.000227   call Smartim_debug_print('b:saved_im = ' . b:saved_im)
    6   0.000060   0.000042   call Smartim_debug_print('<<< Smartim_SelectDefault returned ' . v:shell_error)


FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    6   2.451158   2.451045  Smartim_SelectDefault()
    3   1.810957   0.001447  vimwiki#lst#kbd_o()
    2   1.121454             UpdateWiki()
    6   0.998683   0.998595  Smartim_SelectSaved()
   68   0.325549   0.159666  provider#python3#Call()
   22   0.230005   0.045087  airline#highlighter#highlight()
 1160   0.199446   0.091035  airline#highlighter#exec()
  300   0.193879   0.030343  airline#check_mode()
    4   0.167758   0.000608  <SNR>52_airline_refresh()
    1   0.165883   0.000090  remote#host#Require()
    1   0.165793   0.000084  provider#pythonx#Require()
    1   0.165696             provider#Poll()
    4   0.137285   0.000617  airline#load_theme()
   34   0.123401   0.002495  <SNR>165_completion_begin()
   42   0.113324   0.089302  deoplete#init#_context()
   56   0.111573             UltiSnips#TrackChange()
    2   0.094433   0.000098  <SNR>105_ale_refresh()
    2   0.073487   0.000065  <SNR>106_ws_refresh()
   19   0.072139   0.001674  <SNR>165_completion_async()
    4   0.070579   0.000471  airline#highlighter#load_theme()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    6   2.451158   2.451045  Smartim_SelectDefault()
    2              1.121454  UpdateWiki()
    6   0.998683   0.998595  Smartim_SelectSaved()
    1              0.165696  provider#Poll()
   68   0.325549   0.159666  provider#python3#Call()
   56              0.111573  UltiSnips#TrackChange()
 1160   0.199446   0.091035  airline#highlighter#exec()
   42   0.113324   0.089302  deoplete#init#_context()
   22   0.230005   0.045087  airline#highlighter#highlight()
  305   0.041138   0.036056  airline#extensions#whitespace#check()
 1794   0.059424   0.032311  airline#highlighter#get_highlight()
 1160              0.031644  <SNR>114_CheckDefined()
  578              0.031445  <SNR>114_get_syn()
  300   0.193879   0.030343  airline#check_mode()
   10              0.029943  UltiSnips#SnippetsInCurrentScope()
    1              0.029852  <SNR>157_try_cmd()
 2100              0.023175  airline#util#append()
   85   0.027792   0.018117  <SNR>161_vimoption2python()
  656   0.028307   0.017360  deoplete#custom#_get_option()
  313   0.028048   0.016803  airline#extensions#ale#get()


插件不生效

按照你的安装说明安装后,无效.

独立调用你的im-select命令是有效的.但是在vim里面没有任何效果.
如何调试,需要我提供什么资料吗?

在其他app中切换输入法再切回终端的vim后插件会失效

试了几个切换输入法的插件都有这个问题

版本 neovim v0.4.4
终端 iterm2
OS macos catalina
使用的输入法:mac原生英文/拼音输入法

复现方式:

  1. 编辑完中文按esc回到normal模式
  2. 切换到浏览器
  3. 切换到中文输入法 搜索
  4. 搜索完毕后切换应用回到vim
  5. 按下i进入编辑模式

此时虽然输入法切换回中文了,mac顶部的bar也显示是中文输入法状态,但是只能输入英文 ,需要手动重新点选一下中文输入法

如果要避免这种情况 只能在浏览器输入完中文后手动切换回英语 再切回vim

E484?

快捷键切回的时候会出现:
E484: cannot open file c:\Users\xxxx\AppDate\Local\Temp\VIo6D5C.tmp

啥意思呢?

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.