晚上经过参照网上的解决方法,实践了一下,解决了sublime 在linux下的中文输入问题
1:切换到~目录,然后新建一个sublime_imfix.c的文件
touch sublime_imfix.c
2:编辑sublime_imfix.c文件
gedit sublime_imfix.c
将下面的代码复制到打开的gedit中
#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); }
3:将复制好的代码文件sublime_imfix.c编译成libsublime-imfix.so文件
cd ~ gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
到这一步可能会一个有一个错误说什么“gtk/gtkimcontext.h: 没有那个文件或目录”
这时你新开一个终端执行apt-get install libgtk2.0-dev
4:接下来再次执行
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
5:然后将编译的libsublime-imfix.so文件拷贝到sublime_text所在文件夹
sudo mv libsublime-imfix.so /opt/sublime_text/
6:修改文件/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]"
7::还需要修改文件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"
8:最后,最后,最好 ,打开sublime,切换到中文输入,try
10:shutdown -h now
睡觉,睡觉,睡觉