下面由sublime教程栏目给大家介绍sublime text 3怎么在Ubuntu下支持中文输入,希望对需要的朋友有所帮助!
- 相关依赖软件的安装---sudo apt-get install build-essential libgtk2.0-dev
- 复制下面代码到sublime text 3中,并保存为名为sublime_imfix.c的文件
/* * 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); }
- 在终端找到文件位置,将这个文件编译成共享库libsublime-imfix.so----输入命令
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC - 将libsublime-imfix.so拷贝到sublime_text所在文件夹---sudo mv libsublime-imfix.so /opt/sublime_text/
- 修改文件/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启动,就能在sublime中输入中文了!
最后,为了方便我们直接启动时,也能使用中文输入,我们需要在终端命令打开和修改文件sublime_text.desktop的内容---sudo gedit /usr/share/applications/sublime_text.desktop
[Desktop Entry] Version=1.0 Type=Application Name=Sublime Text GenericName=Text Editor Comment=Sophisticated text editor for code,markup and prose Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text %F" Terminal=false MimeType=text/plain; Icon=sublime-text Categories=TextEditor;Development;Utility; StartupNotify=true Actions=Window;Document; X-Desktop-File-Install-Version=0.22 [Desktop Action Window] Name=New Window Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text -n" OnlyShowIn=Unity; [Desktop Action Document] Name=New File Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text --command new_file" OnlyShowIn=Unity;
将内容替换为上面代码内容,这样,我们就大功告成了!当然,为了稳定,我们还是从终端启动更好!
*注
因为我们会看到两个图标,其中一个启动才是可以输入中文的,另一个则还是不能输入
以上是sublime text 3怎么在Ubuntu下支持中文输入的详细内容。更多信息请关注PHP中文网其他相关文章!

SublimeText需一次性购买,价格70美元,永久使用个人电脑;VSCode免费使用,无许可证费用,但扩展和主题可能需付费。选择时需考虑使用需求和预算。

Sublime Text 可以通过以下步骤汉化:1. 下载汉化包;2. 安装汉化包;3. 重启 Sublime Text;4. 设置默认语言(可选);5. 校验汉化。

删除 Sublime Text 中的插件有两种方法:通过插件管理器删除:选择要删除的插件并右键点击,选择 "删除"。手动删除:导航到用户数据目录,找到插件文件夹并将其拖到回收站或废纸篓中。

在 Sublime Text 中使用 GBK 编码编写代码,需要:1. 设置项目编码为 GBK;2. 新建文件;3. 另存为时选择 GBK 编码;4. 使用 GBK 编码输入代码。

购买 Sublime Text 注册码的步骤如下:访问网站并选择“购买”。选择许可证类型并输入信息。付款并接收包含注册码的电子邮件。打开 Sublime Text,转到“许可证”菜单并粘贴注册码。单击“注册”以激活您的注册码和高级功能。

Sublime Text 提供多种保存代码的方法,包括快捷键(Ctrl S)、菜单栏(File > Save)、工具栏(磁盘图标)和命令面板(Ctrl P)。此外,它还提供自动保存功能,可以定期自动保存打开的文件。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

记事本++7.3.1
好用且免费的代码编辑器

WebStorm Mac版
好用的JavaScript开发工具

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)