之前就载ubuntu14.0.04上安装了sublime,在学习python的时候,基本不怎么使用中文,所以就没有解决它无法进行中文输入的问题,今天心血来潮,想解决一下这个问题,也是为以后少点麻烦,下面我列出我解决的过程与步骤:
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.将上一步的文件进行编译
cd ~ gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
如果如果“NO package 'gek+-2.0' found”,解决办法就是下面这个命令,安装这个包:
sudo apt-get install libgtk2.0-dev
3. 将上一步产生的.so文件移动到/opt/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 "$@" 修改为 #!/bin/sh LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text "$@"
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"
参考资料:
【1】http://jingyan.baidu.com/article/f3ad7d0ff8731609c3345b3b.html
【2】http://louisrb.blog.163.com/blog/static/75680129200992641228460/