先在ubuntu中安裝中文輸入法
選擇搜狗輸入法,下載linux版本,然后進行安裝

image.png
$sudo dpkg -i sogoupinyin_2.2.0.0108_amd64.deb
$sudo apt-get install -f
然后進行設(shè)置:

image.png

image.png
如果沒有漢語選項,可以在Install/Remove Language中添加
最后添加漢語

image.png
設(shè)置完以后重啟系統(tǒng)
image
image
image
此時便可以使用中文輸入法了,接下來在sublime里設(shè)置:
下載sublime :https://download.sublimetext.com/sublime_text_3_build_3176_x64.tar.bz2
解壓后進入目錄,打開終端,輸入 ./sublime_text
image
image
接下來設(shè)置中文輸入的問題:
首先安裝依賴庫:
sudo apt-get install libgtk2.0-dev
在新建文件 sublime_imfix.c
$ gedit sublime_imfix.c
在 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);
}
然后用用 gcc 指令生成共享庫 libsublime-imfix.so
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
最后配置共享庫文件:
在 usr/bin/下新建文件subl
sudo gedit /usr/bin/subl
將下面代碼寫入subl文件中:
#!/bin/sh
LD_PRELOAD=/home/esi/Desktop/sublime_text_3/libsublime-imfix.so exec /home/esi/Desktop/sublime_text_3/sublime_text "$@"

image.png
為subl提供執(zhí)行權(quán)限:
sudo chmod +x /usr/bin/subl
運行subl:
/usr/bin/subl
命令執(zhí)行后,Sublime Text 3 會彈出運行,且可以支持中文輸入。
如果使用鼠標右鍵打開文件時能夠使用中文輸入,還需要修改 Sublime Text 3 目錄中文件 sublime_text.desktop 的內(nèi)容。進入 Sublime Text 3 所在路徑并修改文件,指令如下:
sudo gedit /home/esi/Desktop/sublime_text_3/sublime_text.desktop
將 [Desktop Entry] 中的字符串
Exec=/opt/sublime_text/sublime_text %F
修改為:
Exec=bash -c "LD_PRELOAD=/home/esi/Desktop/sublime_text_3/libsublime-imfix.so exec /home/esi/Desktop/sublime_text_3/sublime_text %F"
將 [Desktop Action Window] 中的字符串:
Exec=/opt/sublime_text/sublime_text -n
修改為:
Exec=bash -c "LD_PRELOAD=/home/esi/Desktop/sublime_text_3/libsublime-imfix.so exec /home/esi/Desktop/sublime_text_3/sublime_text -n"
將 [Desktop Action Document] 中的字符串
Exec=/opt/sublime_text/sublime_text --command new_file
修改為:
Exec=bash -c "LD_PRELOAD=/home/esi/Desktop/sublime_text_3/libsublime-imfix.so exec /home/esi/Desktop/sublime_text_3/sublime_text --command new_file"
即可全部完成