Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to support Chinese input in sublime text 3 under Ubuntu

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "sublime text 3 how to support Chinese input under Ubuntu". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how sublime text 3 supports Chinese input under Ubuntu".

Below, the sublime tutorial column will introduce how sublime text 3 supports Chinese input under Ubuntu. I hope it will be helpful to those who need it!

Installation of related dependent software-sudo apt-get install build-essential libgtk2.0-dev

Copy the following code into sublime text 3 and save it as a file named sublime_imfix.c

/ * * 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+- 2.0`-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 Voidgdk_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 should 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);}

Find the file location in the terminal and compile the file into a shared library libsublime-imfix.so---- input command

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

Copy libsublime-imfix.so to the folder where sublime_text is located-sudo mv libsublime-imfix.so / opt/sublime_text/

Modify the contents of the file / usr/bin/subl-sudo gedit / usr/bin/subl

Set

#! / bin/shexec / opt/sublime_text/sublime_text "$@"

Modify to

#! / bin/shLD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec / opt/sublime_text/sublime_text "$@"

In this way, we start by typing subl from the terminal, and we can enter Chinese in sublime!

Finally, in order to facilitate the use of Chinese input when we start directly, we need to open and modify the contents of the file sublime_text.desktop in the terminal command-sudo gedit / usr/share/applications/sublime_text.desktop

[Desktop Entry] Version=1.0Type=ApplicationName=Sublime TextGenericName=Text EditorComment=Sophisticated text editor for code,markup and proseExec=bash-c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec / opt/sublime_text/sublime_text% F" Terminal=falseMimeType=text/plain;Icon=sublime-textCategories=TextEditor;Development;Utility;StartupNotify=trueActions=Window;Document;X-Desktop-File-Install-Version=0.22 [Desktop Action Window] Name=New WindowExec=bash-c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec / opt/sublime_text/sublime_text-n" OnlyShowIn=Unity [Desktop Action Document] Name=New FileExec=bash-c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec / opt/sublime_text/sublime_text-command new_file" OnlyShowIn=Unity

Replace the content with the above code content, so that we are done! Of course, for the sake of stability, it is better to start from the terminal!

* Note

Because we will see two icons, one of which can be started to enter Chinese, and the other can not be entered.

Thank you for reading, the above is the content of "how sublime text 3 supports Chinese input under Ubuntu". After the study of this article, I believe you have a deeper understanding of how sublime text 3 supports Chinese input under Ubuntu, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report