保存下面的代码到文件sublime_imfix.c(位于~目录)

#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);

}
Ubuntu下Sublime Text 3解决无法输入中文的方法

将上一步的代码编译成共享库libsublime-imfix.so,命令

cd ~

gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC
Ubuntu下Sublime Text 3解决无法输入中文的方法

然后将libsublime-imfix.so拷贝到sublime_text所在文件夹

sudo mv libsublime-imfix.so /opt/sublime_text/
Ubuntu下Sublime Text 3解决无法输入中文的方法

修改文件/usr/bin/subl的内容

sudo gedit /usr/bin/subl

#!/bin/sh

exec /opt/sublime_text/sublime_text "$@"

修改为

#!/bin/sh

LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text "$@"

此时,在命令中执行 subl 将可以使用搜狗for linux的中文输入
Ubuntu下Sublime Text 3解决无法输入中文的方法

为了使用鼠标右键打开文件时能够使用中文输入,还需要修改文件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"

注意:

修改时请注意双引号"",否则会导致不能打开带有空格文件名的文件。

此处仅修改了/usr/share/applications/sublime-text.desktop,但可以正常使用了。

opt/sublime_text/目录下的sublime-text.desktop可以修改,也可不修改。
Ubuntu下Sublime Text 3解决无法输入中文的方法

ubunutu_install_sublime_china的更多相关文章

随机推荐

  1. pku3670 Eating Together

    http://poj.org/problem?id=3670 DP,最长不降子序列,O(n*logn)解法 #include <stdio.h> #define N 30030 int n ...

  2. RabbitMQ (五)主题(Topic) -摘自网络

    虽然使用direct类型改良了我们的系统,但是仍然存在一些局限性:它不能够基于多重条件进行路由选择. 在我们的日志系统中,我们有可能希望不仅根据日志的级别而且想根据日志的来源进行订阅.这个概念类似un ...

  3. webSocket vnc rfb

  4. POJ 2387 Til the Cows Come Home (最短路 dijkstra)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...

  5. android 多线程数据库读写分析与优化

    最新需要给软件做数据库读写方面的优化,之前无论读写,都是用一个 SQLiteOpenHelper.getWriteableDataBase() 来操作数据库,现在需要多线程并发读写,项目用的是2.2的 ...

  6. asp.net中使用swfupload上传大文件

    转载:http://www.cnblogs.com/niunan/archive/2012/01/12/2320705.html 花了一天多时间研究出来的,其实也就是网上下别人的代码然后再自己修修改改 ...

  7. SQL拆分多规则的字符串分离数字。

    --拆分多规则字符串 DECLARE @Codes NVARCHAR(MAX) SET @Codes = '6*BC-007,*BC-016,9*BC-015' --对于*BC-015这种情况,则Qt ...

  8. stack对象与heap对象

    从高地址到低地址,分别是stack,heap,static object,stack地址往下增长,heap地址往上增长.只要记住:stack栈顶地址反而小,就知道往下增长了. 禁止产生堆对象 1.产生 ...

  9. Html+jquery mobile

    打开VS 2013,选择[文件]-[新建]-[项目] 选择框架为.NET Framework4-[ASP.NET MVC4 Web应用程序],点击[确定] 选择[基本],点击[确定] 创建的MVC的项 ...

  10. IOS Note - View Controller(视图控制器)

    Application Delegate(应用程序委托) Application Name: SingleView SingleViewAppDelegate.h #import <UIKit/ ...