不完美解决 macvim 与输入法的困扰 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Aben
V2EX    Vim

不完美解决 macvim 与输入法的困扰

  •  
  •   Aben Jun 24, 2012 6940 views
    This topic created in 5058 days ago, the information mentioned may be changed or developed.
    Mac 下的输入法没有彻底拦截键盘事件,导致在非英文输入法执行normal mode命令的时候,会执行命令...进入 Ex-mode, 或者删除光标所在行「1」之后的代码,这时候都会执行 undo 操作,然后就会文件尾发现之前光标所在行「1」的拷贝。@iceseaboy 同学有丢代码的经历,他尝试过用宏记录启用中文输入法执行jk等命令时真正执行的命令,具体跟 @iceseaboy 同学交流。

    我目前的解决方案是这样的
    1. vimrc 添加
    se imd
    au InsertEnter * se noimd
    au InsertLeave * se imd
    au FocusGained * se imd

    2. Input source options 勾选 "Allow a different one for each document".
    这个在 Setting -> Language & Text -> Input Sources 里设置。

    完美的情况时,vim 获得焦点就禁用输入法,只有进入插入模式才启用输入法,离开禁用。但是标题已经说了,这是个不完美的解决方案:获得焦点(FoucGained)禁止不了输入法!!!这个方法只解决了(1)启用中文输入法时,按i,s能顺利进入插入模式,(2)插入模式输入中文完毕回到普通模式时禁用输入法。

    Alfred 实现了输入字符的时候强制使用U.S. keyboard 或者其它,使用 apple script 或者模拟点击应该可以实现上述的完美解决方法。

    该解决方法已用3个人使用,显著减少了工作流被打断的次数。

    @lotem: 启用鼠须管输入法+上述解决方法时,用i, a 进入插入模式会多一个尖括号()。


    @xell @NemoAlex @vexfisher @vicesa
    Supplement 1    Nov 22, 2012
    12. International *macvim-international*

    When editing non-English text it may be convenient to keep separate keyboard
    layouts for normal and insert mode. This is supported via the 'imd' option on
    Mac OS X 10.5 or later (on 10.4 the 'imd' option support is not as useful as
    it only switches between Roman and non-Roman input sources and it has been
    known not to work very reliably).

    For example: When 'noimd' is enabled (i.e. IM is enabled) the input source is
    saved when toggling between normal and insert mode, so you can use a US layout
    in normal mode then switch to insert mode and choose a Swedish layout. When
    you go back to normal mode the US layout will be selected and when you enter
    insert mode the Swedish layout is selected. This also works when searching
    for text etc. see 'imc', 'imi', 'ims'.

    我现在的配置
    se noimd
    se ims=1
    8 replies    1970-01-01 08:00:00 +08:00
    ybian
        1
    ybian  
       Jun 24, 2012
    嗯,这个设置我也一直在用。平时写代码或少量输入中文时问题不大。最大的问题是需要大量输入中文的情况,每次进入insert模式都要重新调出中文输入法,如果有办法记住上次离开insert时的设置然后重新进入时自动恢复就好了。
    sinxccc
        2/span>
    sinxccc  
       Jun 24, 2012
    我觉得 vim-cocoa 对中文输入法挺好的。不过我vim用的不多
    vexfisher
        3
    vexfisher  
       Jun 24, 2012
    Nice, 用Aben的方案解决了,多谢
    lotem
        4
    lotem  
       Jun 24, 2012
    多 @Aben
    好用。
    鼠管入法在按i a s入插入模式收到了字母,始字。在我用的Vim 7.2.303版本入法候仍示的候字可以上屏,只是入的那字母有示,示了其後的符。道是VIM特意掉了一字符?
    iceseaboy
        5
    iceseaboy  
       Jun 25, 2012
    此方法是目前我可以找到的最完美试用在mac vim中试用中文拼音输入法的方案。
    我最想吐槽的是为何所有中文拼音输入法都不能拦截输入的按键??
    Aben
        6
    Aben  
    OP
       Oct 8, 2012
    鼠管入法已完美解此,非常感 @lotem

    需要在插入模式或者搜索的候入中文,按一下shift即可。
    iceseaboy
        7
    iceseaboy  
       Oct 8, 2012
    可是鼠管此次更新造成的无规律不能输入中文问题还没有解决,尤其在vim和firefox里多见。。
    iceseaboy
        8
    iceseaboy  
       Oct 8, 2012
    需要按多次shift
    去掉之前针对输入法设置的vim配置后,可以了
    但是我讨厌shift的切换方式。
    我最讨厌这种搜狗的切换方式。。。
    About     Help     Advertise     Blog     API     FAQ     Solana     2426 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 43ms UTC 15:47 PVG 23:47 LAX 08:47 JFK 11:47
    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