天天看點

linux vim輸入法切換,完美解決Mac下Vim/Emacs的輸入法切換問題

背景

vi-mode 是一種高效的編輯方式,但是最令人頭疼的莫過于在普通模式下輸入指令的時候卻被輸入法擋住,對于我這種經常忘記切輸入法的人來說非常痛苦。

為了解決這種問題,很早以前就有了 vim-scripts/fcitx.vim (for Vim)和 cute-jumper/fcitx.el (for Emacs)。利用插件和 fcitx

進行溝通,讓輸入法随着使用者的需要自動改變。

但是 fcitx 是 Linux only 的,OS X 下無法使用。

fcitx-remote

是 fcitx 提供的一個指令行小工具,用于在指令行下控制輸入以及擷取輸入法狀态。早期版本的 fcitx.vim

和 fcitx.el 通過這個程式來和 fcitx 進行互動。于是我受到啟發,如果在 OS X 下實作一個 fcitx-remote,和 fcitx

保持一緻的使用方法, fcitx.vim 和 fcitx.el 就可以在 OS X 直接使用了。是以有了這個項目:CodeFalling/fcitx-remote-for-osx

安裝

homebrew

homebrew 的 core repo 要求 30 天以上的 Github 項目才能加入,現在可以通過 brew tap

安裝。brew tap codefalling/fcitx-remote-for-osxbrew install codefalling/fcitx-remote-for-osx/fcitx-remote-for-osx --with-baidu-pinyin

--with-baidu-pinyin表示百度拼音。

你可以使用 brew info codefalling/fcitx-remote-for-osx/fcitx-remote-for-osx來檢視支援其他輸入法的選項。

==> Options

--with-baidu-pinyin

Build fcitx-remote for osx with baidu-pinyin support

--with-baidu-wubi

Build fcitx-remote for osx with baidu-wubi support

--with-osx-pinyin

Build fcitx-remote for osx with osx-pinyin support

--with-qq-wubi

Build fcitx-remote for osx with qq-wubi support

--with-sogou-pinyin

Build fcitx-remote for osx with sogou-pinyin support

--with-squirrel-rime

Build fcitx-remote for osx with squirrel-rime support

手工安裝

git clone https://github.com/CodeFalling/fcitx-remote-for-osx cd fcitx-remote-for-osx xcodebuild GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS [email protected]\"com.baidu.inputmethod.BaiduIM.pinyin\"' install

編譯完成後可執行檔案會被安裝到 /usr/local/bin/fcitx-remote

建構指令看起來比較長,是因為要定制所用的中文輸入法,對應輸入法的 imname

可以在 Github 看到,如果表裡沒有你用的輸入法,你可以先安裝了fcitx-remote,然後用 fcitx-remote -n來擷取目前的輸入法名,歡迎以任何形式向我補充。

我使用的是百度拼音,如果你使用其他輸入法,編譯參數要做響應的修改。

二進制檔案

Emacs

由于我自己是 emacs 使用者是以先提 emacs, fcitx-remote可以和 cute-jumper/fcitx.el 配合使用, 但是不要使用 =(fcitx-prefix-keys-turn-on)= 和 =(fcitx-prefix-keys-setup)= (即不要直接使用 =fcitx-default-setup= 什麼的),會導緻 emacs 假死,原因不詳。我自己使用的配置是

之前使用的時候會卡死,後來發現是因為我用的 fish-shell,在 emacs 的配置裡加上一句 (setq shell-file-name "bash") ,問題就完美解決了。

Vim

本來以為 vim 是使用不了這個小工具的,但是後來發現老版本的 fcitx.vim同樣使用 fcitx-remote,然後簡單的修改下(不然會很卡),放在了CodeFalling/fcitx-vim-osx 。可以直接通過 vundle安裝,這個版本也可以直接在 Linux 下使用。回報使用中碰到任何問題,歡迎去 CodeFalling/fcitx-remote-for-osx 開 issue 或者直接評論。