作者:wangtao | 来源:互联网 | 2023-08-21 16:35
一、“Sublime Text 3”的安装
1. 官网下载程序解压到自己的软件目录下(比如"~/Software")
$ cd ~/Software/sublime_text_3
$ ./sublime_text
3. 配置全局运行
创建“/usr/bin/subl”文件,文件内容如下:
#!/bin/sh
exec ~/Software/sublime_text_3/sublime_text "$@"
进入 /usr/bin 目录下赋予 subl 文件可执行的权限:
$ cd /usr/bin
$ sudo chmod +x subl
这样在任何目录下执行 subl
都可以运行Sublime Text了
二、解决Sublime Text 3中无法输入中文的问题
1. 安装“搜狗输入法 for linux”
请参考:Ubuntu安装“搜狗输入法 for linux”
2. 创建文件“~/sublime_imfix.c”,文件内容如下:
#include
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. 生成共享库,执行如下命令:
$ sudo apt-get install libgtk2.0-dev
$ cd ~
$ gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
$ sudo mv libsublime-imfix.so ~/Software/sublime_text_3/
4. 修改文件“/usr/bin/subl”,内容如下:
#!/bin/sh
LD_PRELOAD=~/Software/sublime_text_3/libsublime-imfix.so exec ~/Software/sublime_text_3/sublime_text "$@"
此时输入 subl
打开的Sublime Text已经可以输入中文了。若想使鼠标右键打开文件时能够支持中文输入,还需要下一步的修改。
5. 修改文件“~/Software/sublime_text_3/sublime_text.desktop”:
将[Desktop Entry]中的字符串Exec=~/Software/sublime_text_3/sublime_text %F
修改为
Exec=bash -c "LD_PRELOAD=~/Software/sublime_text_3/libsublime-imfix.so exec ~/Software/sublime_text_3/sublime_text %F"
将[Desktop Action Window]中的字符串Exec=~/Software/sublime_text_3/sublime_text -n
修改为
Exec=bash -c "LD_PRELOAD=~/Software/sublime_text_3/libsublime-imfix.so exec ~/Software/sublime_text_3/sublime_text -n"
将[Desktop Action Document]中的字符串Exec=~/Software/sublime_text_3/sublime_text --command new_file
修改为
Exec=bash -c "LD_PRELOAD=~/Software/sublime_text_3/libsublime-imfix.so exec ~/Software/sublime_text_3/sublime_text --command new_file"
ALL DONE!
文章参考:Ubuntu 16.04 下 Sublime Text 3 的安装和中文配置