Solve the problem that sublime cannot input Chinese Characters in Ubuntu, using tusublime
Solve the problem that sublime cannot enter Chinese Characters in Ubuntu.
After installing sublime in Ubuntu, you cannot enter Chinese characters, but can enter it normally in other software. This is a sublime bug, the solution is to automatically add a dynamic correction library before running sublime through shell. The solution is as follows:
Enter a directory such ~ :
cd
Create a C source code
subl sublime-imfix.c
Paste the following code:
#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);}
Install the dependency package before compilation. Run the following command:
sudo apt-get install build-essentialsudo apt-get install libgtk2.0-dev
Then compile the C file:
gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
Next, tell the program link to this before each sublime program is run. so library file can be input in sublime Chinese, its command is LD_PRELOAD =/opt/sublime_text/libsublime-imfix.so exec/opt/sublime_text "$ @", /opt/sublime_text/is the default directory for sublime installation. Command Line subl or Dash Sublime Text, or open with> sublime text in the file browser, they can start the sublime program, but they do not have to look for their startup portal, and then change it one by one. They all rely on the execution of/opt/sublime_text. With this feature, the/opt/sublime_text binary files are saved separately, then, write a shell script named/opt/sublime_text, which tells the program link before executing the/opt/sublime_text binary code before creating the shell script. so to modify the library file. The process is as follows:
Cd/opt/sublime_text/sudo mv sublime_text sublime_text0sudo vim sublime_text # If you are not familiar with vim, sudo gedit sublime_text
Write the following statement in a row and save it:
LD_PRELOAD =/opt/sublime_text/libsublime-imfix.so exec/opt/sublime_text/sublime_text0 "$ @"
sudo chmod +x sublime_text
Now, you can enter Chinese Characters in sublime.