1.首先下载搜狗输入法
http://pinyin.sogou.com/linux/
帮助请看下面的文章:http://pinyin.sogou.com/linux/help.php
2.然后安装sublime text 3
下载http://c758482.r82.cf2.rackcdn.com/sublime-text_build-3059_amd64.deb文件,下载后双击即会自动使用默认的安装软件安装。
3.安装相关的依赖软件
sudo apt-get install build-essential libgtk2.0-dev
4.开始操作让sublime支持中文输入法
操作前条件:本经验是在ubuntu kylin14.04下的环境,已经有搜狗输入法for linux和Sublime text 3安装成功在你的电脑
1@ : cd ~
2@ : touch sublime_imfix.c(一定要注意是下划线,而不是横杠)
5.将下面的代码粘贴进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);
}
6.将上面的文件进行编译
1@ : cd <pre name="code" class="plain"> 2@: <em><strong>gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC</strong></em>
7.编译成功后执行下面命令将文件移到libsublime-imfix.so拷贝到sublime_text所在文件夹
1@:sudo mv libsublime-imfix.so /opt/sublime_text/
8.修改文件/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的中文输入9.为了使用鼠标右键打开文件时能够使用中文输入,还需要修改文件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可以修改,也可不修改。
10.哈哈,,通过以上步骤注销你的机器,然后你就会惊奇的发现sublime能输入中文了,而且还是搜狗的哦,亲!!!