码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu下Sublime Text 3解决无法输入中文的方法

时间:2014-11-04 17:42:13      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   io   color   ar   os   使用   for   

环境:

  • Ubuntu14.04

  • 搜狗输入法 for Linux

  • Sublime text 3

提示:编译请在非root下进行

本经验目前在Ubuntu14.04环境下,已有搜狗输入法 for Linux和Sublime Text 3的情况下安装成功。

bubuko.com,布布扣


  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);

    }

    bubuko.com,布布扣

  2. 将上一步的代码编译成共享库libsublime-imfix.so,命令

    cd ~

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

    bubuko.com,布布扣

  3. 然后将libsublime-imfix.so拷贝到sublime_text所在文件夹

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

    bubuko.com,布布扣

  4. 修改文件/usr/bin/subl的内容

    sudo gedit /usr/bin/subl

    #!/bin/sh

    exec /opt/sublime_text/sublime_text "$@"

    修改为

    #!/bin/sh

    LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text "$@"

    此时,在命令中执行 subl 将可以使用搜狗for linux的中文输入

    bubuko.com,布布扣

  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可以修改,也可不修改。

    bubuko.com,布布扣

  6. 6

    经过以上步骤我们能在Sublime中输入中文了。

    bubuko.com,布布扣


Ubuntu下Sublime Text 3解决无法输入中文的方法

标签:des   style   http   io   color   ar   os   使用   for   

原文地址:http://my.oschina.net/u/1792865/blog/340692

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!