一、下载
下载地址:
https://www.sublimetext.com/3
下载完成后,文件为:
二、安装
1.解压:
在终端中执行以下命令,对文件进行解压,解压文件路径为你终端当前所在位置:
tar -xvvf sublime_text_3_build_3126_x64.tar.bz
在这里,解压的文件名为:sublime_text_3,
为了后续更改中文输入和配置方便,在这里将文件名更改为sublime_text:
mv sublime_text_3 sublime_text
2.移动路径
解压完成后,将sublime_text文件移动至/opt/目录下:
mv sublime_text /opt/
3.创建快捷键执行
至此,sublime已经可以打开使用了,为了方便右键快捷打开文本,这里需要添加快捷键执行至系统中:
cp /opt/sublime_text/sublime_text.desktop /usr/share/applications
到这里,sublimeText已经安装完成并且可以使用了,但是由于与ubuntu系统的兼容性问题,不能输入中文,需要进行相关配置如下。
三、配置输入中文
这里默认当前ubuntu系统已经安装了搜狗输入法,具备中文输入的环境,但是sublimeText中却无法输入中文。
1.依赖文件安装
终端执行:
sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev
2.新建sublime-imfix.c文件(路径无要求),其代码如下:
/*
sublime-imfix.c
Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
By Cjacker Huang
gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
LD_PRELOAD=./libsublime-imfix.so subl
*/
#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);
}
3. 编译共享内库 libsublime-imfix.so
终端执行,需进入sublime-imfix.c所在文件夹:
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
这里我在编译过程出现错误,提示找不到sublime-imfix.c文件中的头文件,原因是因为由于交叉编译需要改变了系统的环境变量,在这里恢复系统的系统变量即可。
4. 设置 LD_PRELOAD 并启动 Sublime Text:
终端执行:
LD_PRELOAD=./libsublime-imfix.so subl
5. 将libsublime-imfix.so移动至/opt/sublime_text/文件夹中:
终端执行:
mv libsublime-imfix.so /opt/sublime_text/
6.修改右键快捷设置:
用sublimeText打开文件/usr/share/applications/sublime_text.desktop, 作以下更改:
[Desktop Entry]
[...]
Exec=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text %F
[...]
[Desktop Action Window]
[...]
Exec=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text -n
[...]
[Desktop Action Document]
[...]
Exec=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text --command new_file
[...]
7. 修改 /usr/bin/subl 为:
#!/bin/sh
export LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so
exec /opt/sublime_text/sublime_text "$@"
重启电脑,就可以看到sublimeText可以输入中文了,但是不会显示中文框,这个问题暂时没有找到解决办法,期待大神能够给予方法。
四、卸载
1. 终端卸载:
sudo apt-get remove sublime_text
2.找不到sublimeText,对文件直接操作:
删除/opt/sublime_text文件夹:
sudo rm -rf /opt/sublime_text
删除配置文件:
sudo rm -rf /home/user/.config/sublime_text
删除其他相关文件:
然后搜索其他的sublime_text相关文件,用rm -rf进行逐一删除:
sudo find / -name sublime*
或者直接删除所有与sublime相关的文件(慎用!!!):
find . -type f -name "sublime*" -exec rm -rf {} \;
五、破解
----- BEGIN LICENSE -----
sgbteam
Single User License
EA7E-1153259
8891CBB9 F1513E4F 1A3405C1 A865D53F
115F202E 7B91AB2D 0D2A40ED 352B269B
76E84F0B CD69BFC7 59F2DFEF E267328F
215652A3 E88F9D8F 4C38E3BA 5B2DAAE4
969624E7 DC9CD4D5 717FB40C 1B9738CF
20B3C4F1 E917B5B3 87C38D9C ACCE7DD8
5F7EF854 86B9743C FADC04AA FB0DA5C0
F913BE58 42FEA319 F954EFDD AE881E0B
------ END LICENSE ------
文章中如有不妥之处,欢迎各位朋友指正和建议。