Sublime Text 2 Linux 版一直都没有解决中文输入这个问题。
目前中文输入有三种方案,分别是:
方案一:使用小小输入法
小小输入法新版本已经支持再Sublime Text 下输入中文
关于小小输入法的安装以及简介:
http://blog.ubuntusoft.com/small-input.html
http://forum.ubuntu.org.cn/viewtopic.php?t=226677
方案二:打开另外一个可以输入中文的输入框,输入中文后拷贝进Sublime Text 2
有人制作了一个Sublime Text 2的插件(InputHelper),可以快捷调用一个输入框,输入后确定就自动复制到ST2 内。
InputHelper 的安装方法:
cd ~/.config/sublime-text-2/Packages git clone https://github.com/xgenvn/InputHelper.git |
然后重启Sublime Text 2。需要输入中文的时候,使用快捷键:
Ctrl + Shift + Z |
即可调出输入框,输入后自动插入。
此方法适用所有输入法。
方案三:通过打补丁的方式,让Sublime Text 2 支持Fcitx 输入法
首先我们需要通过PPA 安装ST2(非官方下载的免安装包):
sudo add-apt-repository ppa:webupd8team/sublime-text-2 sudo apt-get update sudo apt-get install sublime-text |
然后打补丁:
将下面代码复制下来,并保存为sublime-imfix.c(存放于/home/username,即你的主目录)
/* sublime-imfix.c Use LD_PRELOAD to interpose some function to fix sublime input method support for linux. By Cjacker Huang <jianzhong.huang at i-soft.com.cn> 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 <gtk/gtk.h> #include <gdk/gdkx.h> 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 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); } |
打开终端,安装编译时候需要的环境:
sudo apt-get install build-essential sudo apt-get install libgtk2.0-dev |
然后编译sublime_imfix.c(先要在终端进入sublime_imfix.c 所在目录):
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC |
编译后会得到libsublime-imfix.so ,我建议你直接把libsublime-imfix.so 留在你的主目录即可。
然后修改ST2的启动配置:
sudo gedit /usr/share/applications/sublime-text-2.desktop |
找到
Exec=/usr/bin/sublime-text-2 %F |
修改为
Exec=bash -c ‘LD_PRELOAD=/home/username/libsublime-imfix.so /usr/bin/sublime-text-2‘ %F |
找到
Exec=/usr/bin/sublime-text-2 --new-window |
修改为
Exec=bash -c ‘LD_PRELOAD=/home/username/libsublime-imfix.so /usr/bin/sublime-text-2‘ --new-window |
注意,其中/home/username/libsublime-imfix.so 修改为你编译生成的libsublime-imfix.so 的所在路径。
注意,新版本的ST2 的启动命令改为subl (上面教程中是旧版本的sublime-text-2),因此修改的时候,把sublime-text-2 改为 subl
然后保存,重启ST2 即可。