V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Aben
V2EX  ›  Vim

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

  •  
  •   Aben · 2012-06-24 01:14:15 +08:00 · 6105 次点击
    这是一个创建于 4325 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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
    第 1 条附言  ·  2012-11-22 11:43:23 +08:00
    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 条回复    1970-01-01 08:00:00 +08:00
    ybian
        1
    ybian  
       2012-06-24 06:31:54 +08:00
    嗯,这个设置我也一直在用。平时写代码或少量输入中文时问题不大。最大的问题是需要大量输入中文的情况,每次进入insert模式都要重新调出中文输入法,如果有办法记住上次离开insert时的设置然后重新进入时自动恢复就好了。
    sinxccc
        2
    sinxccc  
       2012-06-24 06:59:22 +08:00
    我觉得 vim-cocoa 对中文输入法挺好的。不过我vim用的不多
    vexfisher
        3
    vexfisher  
       2012-06-24 13:02:12 +08:00
    Nice, 用Aben的方案解决了,多谢
    lotem
        4
    lotem  
       2012-06-24 16:03:22 +08:00
    多謝 @Aben
    好用。
    鼠鬚管輸入法在按i a s進入插入模式時確實收到了字母鍵,並開始組字。在我用的Vim 7.2.303這個版本裏輸入法候仍顯示對應的候選字並可以上屏,只是輸入的那個字母沒有顯示,單單顯示了其後的›符號。難道是VIM特意從緩衝區刪掉了一個字符?
    iceseaboy
        5
    iceseaboy  
       2012-06-25 12:20:45 +08:00
    此方法是目前我可以找到的最完美试用在mac vim中试用中文拼音输入法的方案。
    我最想吐槽的是为何所有中文拼音输入法都不能拦截输入的按键??
    Aben
        6
    Aben  
    OP
       2012-10-08 11:01:26 +08:00
    鼠鬚管輸入法已經完美解決此問題,非常感謝 @lotem

    需要在插入模式或者搜索的時候輸入中文,按一下shift即可。
    iceseaboy
        7
    iceseaboy  
       2012-10-08 14:20:23 +08:00
    可是鼠鬚管此次更新造成的无规律不能输入中文问题还没有解决,尤其在vim和firefox里多见。。
    iceseaboy
        8
    iceseaboy  
       2012-10-08 14:48:55 +08:00
    需要按多次shift
    去掉之前针对输入法设置的vim配置后,可以了
    但是我讨厌shift的切换方式。
    我最讨厌这种搜狗的切换方式。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2846 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:03 · PVG 15:03 · LAX 00:03 · JFK 03:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.