Ubuntu下Sublime Text 3解決無法輸入中文的方法

來源:互聯網
上載者:User

標籤:des   style   http   io   color   ar   os   使用   for   

環境:

  • Ubuntu14.04

  • 搜狗IME for Linux

  • Sublime text 3

提示:編譯請在非root下進行

本經驗目前在Ubuntu14.04環境下,已有搜狗IME for Linux和Sublime Text 3的情況下安裝成功。


  1. 儲存下面的代碼到檔案sublime_imfix.c(位於~目錄)

    #include <gtk/gtkimcontext.h>

    void gtk_im_context_set_client_window (GtkIMContext *context,

             GdkWindow    *window)

    {

     GtkIMContextClass *klass;

     g_return_if_fail (GTK_IS_IM_CONTEXT (context));

     klass = GTK_IM_CONTEXT_GET_CLASS (context);

     if (klass->set_client_window)

       klass->set_client_window (context, window);

     g_object_set_data(G_OBJECT(context),"window",window);

     if(!GDK_IS_WINDOW (window))

       return;

     int width = gdk_window_get_width(window);

     int height = gdk_window_get_height(window);

     if(width != 0 && height !=0)

       gtk_im_context_focus_in(context);

    }

  2. 將上一步的代碼編譯成共用庫libsublime-imfix.so,命令

    cd ~

    gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC

  3. 然後將libsublime-imfix.so拷貝到sublime_text所在檔案夾

    sudo mv libsublime-imfix.so /opt/sublime_text/

  4. 修改檔案/usr/bin/subl的內容

    sudo gedit /usr/bin/subl

    #!/bin/sh

    exec /opt/sublime_text/sublime_text "[email protected]"

    修改為

    #!/bin/sh

    LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text "[email protected]"

    此時,在命令中執行 subl 將可以使用搜狗for linux的中文輸入

  5. 為了使用滑鼠右鍵開啟檔案時能夠使用中文輸入,還需要修改檔案sublime_text.desktop的內容。

    命令

    sudo gedit /usr/share/applications/sublime_text.desktop

    將[Desktop Entry]中的字串

    Exec=/opt/sublime_text/sublime_text %F

    修改為

    Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text %F"

    將[Desktop Action Window]中的字串

    Exec=/opt/sublime_text/sublime_text -n

    修改為

    Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text -n"

    將[Desktop Action Document]中的字串

    Exec=/opt/sublime_text/sublime_text --command new_file

    修改為

    Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text --command new_file"

    注意:

    修改時請注意雙引號"",否則會導致不能開啟帶有空格檔案名稱的檔案。

    此處僅修改了/usr/share/applications/sublime-text.desktop,但可以正常使用了。

    opt/sublime_text/目錄下的sublime-text.desktop可以修改,也可不修改。

  6. 6

    經過以上步驟我們能在Sublime中輸入中文了。


Ubuntu下Sublime Text 3解決無法輸入中文的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.