分享一个 neovim 自动切换输入法的 lua 脚本 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yuancoder
V2EX    Vim

分享一个 neovim 自动切换输入法的 lua 脚本

  •  2
     
  •   yuancoder Apr 7, 2023 2607 views
    This topic created in 1123 days ago, the information mentioned may be changed or developed.

    使用了一段时间 rime 输入法, 这个输入法支持 vim 模式, 用起来还是挺方便的,但是打字效果太差了。
    最后还是回归了原生的输入法,为了解决切换输入法的问题写了个 lua 脚本。
    这里没有使用 im-select 是因为 im-select 在 mac 上切换会偶尔失效,所以我用了这个 macism

    -- 记录当前输入法 Current_input_method = vim.fn.system("/usr/local/bin/macism") -- 切换到英文输入法 function Switch_to_English_input_method() Current_input_method = vim.fn.system("/usr/local/bin/macism") if Current_input_method ~= "com.apple.keylayout.ABC\n" then vim.fn.system("/usr/local/bin/macism com.apple.keylayout.ABC") end end -- 设置输入法 function Set_input_method() if Current_input_method ~= "com.apple.keylayout.ABC\n" then vim.fn.system("/usr/local/bin/macism " .. string.gsub(Current_input_method, "\n", "")) end end -- 进入 normal 模式时切换为英文输入法 vim.cmd([[ augroup input_method autocmd! autocmd InsertEnter * :lua Set_input_method() autocmd InsertLeave * :lua Switch_to_English_input_method() augroup END ]]) 
    4 replies    2023-08-16 22:41:34 +08:00
    knightdf
        1
    knightdf  
       Apr 7, 2023
    mac 切换输入法不就按一下 cap 么,还需要搞这么复杂?
    yuancoder
        2
    yuancoder  
    OP
       Apr 7, 2023
    @knightdf #1 每次按 esc 之前需要多按一次 cap ,进入 insert 模式又要按一次,而且 hhkb 没有 cap 键
    saikete
        3
    saikete  
       May 18, 2023
    刚看了有人分享的 im-select 版就看到了老哥分享的 macism 版,hhhh ,支持,我也是刚刚搞好
    fang2hou
        4
    fang2hou  
       Aug 16, 2023
    im-select.nvim 的配置里把命令换成 macism 就非常好用了。
    About     Help     Advertise     Blog     API     FAQ     Solana     2808 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 30ms UTC 03:01 PVG 11:01 LAX 20:01 JFK 23:01
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86