首页 > 代码库 > 解决 Ubuntu 16.04 LTSSublime text3中文问题
解决 Ubuntu 16.04 LTSSublime text3中文问题
解决Sublime text3文问题
一、解决显示中文乱码问题
1、安装包管理器
使用Ctrl+~快捷键或者通过View-->Show Console菜单打开命令行,粘贴如下代码
import urllib.request,os; pf = ‘Package Control.sublime-package‘; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), ‘wb‘).write(urllib.request.urlopen( ‘http://sublime.wbond.net/‘ + pf.replace(‘ ‘,‘ ‘)).read())
顺利的话,此时就可以在Preferences菜单下看到Package Settings和Package Control两个菜单了
2、安装乱码处理插件
调用ctrl+shift+p,输入:install package,回车,在稍后弹出的安装包框中搜索:ConvertToUTF8或GBK Encoding Support,选择点击安装;
由于 Sublime Text 3 内嵌的 Python 限制,ConvertToUTF8 可能无法正常工作。你可以安装本插件来解决这一问题:
使用 Package Control 查找 Codecs33 进行自动下载安装与更新。
二、解决sublime text3无法输中文问题
1、系统已成功安装搜狗输入法
2、保存下面的代码到文件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);
}
3、在终端输入
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
4、如果出现错误,则输入以下命令后再编译
sudo apt-get install libgtk2.0-dev
5、将上一步的代码编译成共享库libsublime-imfix.so,命令
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
6、将libsublime-imfix.so拷贝到sublime_text所在文件夹
sudo mv libsublime-imfix.so /opt/sublime_text/
7、修改文件/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 将可以使用搜狗for linux的中文输入
8、为了使用鼠标右键打开文件时能够使用中文输入,还需要修改文件sublime_text.desktop的内容,两个文件内容一致
#sudo gedit /usr/share/applications/sublime_text.desktop
#sudo gedit /home/xnnet/.local/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=/opt/sublime_text/sublime_text %F
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;
StartupNotify=true
Actions=Window;Document;
[Desktop Action Window]
Name=New Window
#Exec=/opt/sublime_text/sublime_text -n
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=/opt/sublime_text/sublime_text --command new_file
Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text --command new_file"
OnlyShowIn=Unity;
本文出自 “XnNetBlog” 博客,请务必保留此出处http://xnnet.blog.51cto.com/12795469/1931914
解决 Ubuntu 16.04 LTSSublime text3中文问题