After installing SublimeText3 in Ubuntu14.04, I found that Chinese characters are not supported. So I searched the internet and found that many people encountered the same problem, but the solution should be the same. The following is a summary of the installation and solution: 1. there are multiple installation methods for SublimeText3. This article describes how to download 64-bit data from the official website. deb file, specifically http: // c758482.r82. cf2
After installing Sublime Text 3 in Ubuntu 14.04, I found that Chinese characters are not supported. So I searched the internet and found that many people encountered the same problem, however, there should be only one solution. The following is a summary of the installation and solution:
1. Install SublimeText 3
There are multiple installation methods. This document describes how to download the 64-bit. deb file from the official website, specifically the release.
2. Install related dependent Software
Sudo apt-get install build-essential libgtk2.0-dev
3. Copy the following code to the sublime_imfix.c file, which must be created by yourself and put anywhere.
/*
* Sublime-imfix.c
* Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
* By Cjacker Huang *
*
* Gcc-shared-o libsublime-imfix.so sublime_imfix.c 'pkg-config -- libs -- cflags gtk +-6666'-fPIC
* LD_PRELOAD =./libsublime-imfix.so sublime_text
*/
# Include
# Include
Typedef GdkSegment GdkRegionBox;
Struct _ GdkRegion
{
Long size;
Long numRects;
GdkRegionBox * rects;
GdkRegionBox extents;
};
GtkIMContext * local_context;
Void
Gdk_region_get_clipbox (const GdkRegion * region,
GdkRectangle * rectangle)
{
G_return_if_fail (region! = NULL );
G_return_if_fail (rectangle! = NULL );
Rectangle-> x = region-> extents. x1;
Rectangle-> y = region-> extents. y1;
Rectangle-> width = region-> extents. x2-region-> extents. x1;
Rectangle-> height = region-> extents. y2-region-> extents. y1;
GdkRectangle rect;
Rect. x = rectangle-> x;
Rect. y = rectangle-> y;
Rect. width = 0;
Rect. height = rectangle-> height;
// The caret width is 2;
// Maybe sometimes we will make a mistake, but for most of the time, it shocould be the caret.
If (rectangle-> width = 2 & GTK_IS_IM_CONTEXT (local_context )){
Gtk_im_context_set_cursor_location (local_context, rectangle );
}
}
// This is needed, for example, if you input something in file dialog and return back the edit area
// Context will lost, so here we set it again.
Static GdkFilterReturn event_filter (GdkXEvent * xevent, GdkEvent * event, gpointer im_context)
{
XEvent * xev = (XEvent *) xevent;
If (xev-> type = KeyRelease & GTK_IS_IM_CONTEXT (im_context )){
GdkWindow * win = g_object_get_data (G_OBJECT (im_context), "window ");
If (GDK_IS_WINDOW (win )){
Gtk_im_context_set_client_window (im_context, win );
}
}
Return GDK_FILTER_CONTINUE;
}
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 );
}
If (! GDK_IS_WINDOW (window )){
Return;
}
G_object_set_data (G_OBJECT (context), "window", window );
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 );
Local_context = context;
}
Gdk_window_add_filter (window, event_filter, context );
}
Compile the file according to the comments on the file header and enter the directory where the file is stored in the terminal. Enter the following command:
Gcc-shared-o libsublime-imfix.so sublime_imfix.c 'pkg-config -- libs -- cflags gtk +-1000'-fPIC
Finally, get the libsublime-imfix.so shared library in the current directory.
4. Chinese Input
The Chinese Input Method (sogou Input Method for linux) is installed by default ). After getting the library libsublime-imfix.so in step 1, first try to use the Chinese Input Method, enter the following command in the terminal:
LD_PRELOAD =./libsublime-imfix.so subl # subl is the program startup command after installing SublimeText 3
If everything works, you can enter the sogou input method after startup.
5. For convenience
It is inconvenient to enter LD_PRELOAD every time in step 1. Here we provide a simple way to modify the icon connection to quickly open SublimeText. Copy the libsublime-imfix.so to the default path of the System Library:
Sudo cp libsublime-imfix.so/usr/lib/
Modify the/usr/share/applications/sublime_text.desktop File
Sudo vim/usr/share/applications/sublime_text.desktop
Open Exec =/opt/sublime_text % F
Exec = bash-c 'LD _ PRELOAD =/usr/lib/libsublime-imfix.so/opt/sublime_text '% F
Change Exec =/opt/sublime_text-n
Exec = bash-c 'LD _ PRELOAD =/usr/lib/libsublime-imfix.so/opt/sublime_text '-n
In this way, SublimeText 3 can be opened in a shortcut to support Chinese input.
Note: The fifth step is only applicable to the installation of the. deb file. If the source code is used for installation, You need to modify it. Write a script to add LD_PRELOAD.
More about Sublime Text:
Ubuntu install code editor Sublime Text 3 (Build 3083) http://www.linuxidc.com/Linux/2015-03/115534.htm
Dynamic Graph Display 16 Sublime Text Shortcut Key Usage http://www.linuxidc.com/Linux/2014-12/110930.htm
Ubuntu 12.10 install and crack Sublime Text 2Http://www.linuxidc.com/Linux/2013-07/86898.htm
Ubuntu 13.04 install Sublime Text 2 http://www.linuxidc.com/Linux/2013-05/84228.htm
Code artifact-Sublime Text package management tools and extensions Daquan http://www.linuxidc.com/Linux/2013-10/91701.htm
How to Develop Sublime Text 2 plug-in http://www.linuxidc.com/Linux/2013-09/90046.htm
Install and crack Sublime Text 2 editor http://www.linuxidc.com/Linux/2013-08/89452.htm in Windows Mac Linux
Text Editor Sublime Text experience http://www.linuxidc.com/Linux/2013-08/89326.htm
Sublime Text: Click here
Sublime Text: Click here
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2016-01/127340.htm