侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

ubuntu下sublime text 3 中文输入

2023-12-15 星期五 / 0 评论 / 0 点赞 / 130 阅读 / 4508 字

1:切换到~目录,然后新建一个sublime_imfix.c的文件命令:touch sublime_imfix.c或者直接去手动新建2:编辑sublime_imfix.c文件gedit sublime

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文件

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/shexec /opt/sublime_text/sublime_text "$@"

改为

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

此时,在命令中执行 subl 将可以使用搜狗for linux的中文输入,但此时使用其他方式依然无法正常输入中文

7:为了使用鼠标右键打开文件时能够使用中文输入,还需要修改文件sublime_text.desktop的内容

命令

sudo nano /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"

[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;

![输入图片说明](https://static.oschina.net/uploads/img/201610/25132646_SKUh.png "在这里输入图片标题")>    修改时请注意双引号”“,否则会导致不能打开带有空格文件名的文件。    此处仅修改了/usr/share/applications/sublime-text.desktop,但可以正常使用了。    opt/sublime_text/目录下的sublime-text.desktop可以修改,也可不修改。

广告 广告

评论区