最近在使用sublime text 3打开一个项目的源文件时,里面所有的中文注释都显示成乱码了。网上的一些教程有帮助,但并没有完全解决我的问题,后面自己就结合了多篇教程及下载一些文件,才一步一步弄好。现在把这些步骤都整合记录下来,方便以后查阅。 

        首先需要先安装Package Control,它的安装方法有两个,一个是通过Sublime Text的终端执行代码,官网(https://packagecontrol.io/installation#st3)的描述是这样的:

"The simplest method of installation is through the Sublime Text console. The console is accessed via the ctrl+` shortcut or the View > Show Consolemenu. Once open, paste the appropriate Python code for your version of Sublime Text into the console."

        意思是按Control + ~ 打开Sublime Text的终端,里面有个输入框;接着在输入框中复制以下代码:

sublime text 3的代码是这个:

import urllib.request,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf282' + 'd0e7a3098092775ccb37ca9d6b2e4b7d'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

        但是我在执行完以上代码后sublime会卡死,卡死一会儿之后终端就给报错了,这里安装失败,之后我就选择手工安装的方式。官网上手工安装的说明:

If for some reason the console installation instructions do not work for you (such as having a proxy on your network), perform the following steps to manually install Package Control:

  1. Click the Preferences > Browse Packages… menu
  2. Browse up a folder and then into the Installed Packages/ folder
  3. Download Package Control.sublime-package and copy it into the Installed Packages/ directory
  4. Restart Sublime Text

        意思是打开Sublime Text的系统设置Preferences,点开里面的Browse Packages。在弹出的窗口中前往上一层文件夹,打开Installed Packages文件夹,把下载好的Package Control.sublime-package文件放进里面即可安装好Package Control,然后重启Sublime Text生效。

这里附上Package Control.sublime-package的链接和提取码:

链接:https://pan.baidu.com/s/1ayv2lFpCUVspks3SQycvpg  密码:yxgx。将下载好的压缩文件进行解压,在把里面的Package Control.sublime-package文件放到Sublime Text 3的Installed Packages目录下。

        安装好之后在sublime text 3中按command + shift + p打开Package Control输入框,选择Install Package,如下图:

一步一步解决Mac os下Sublime Text 3中的中文显示乱码问题

        此时我的sublime弹出了”There is no packages available for installation“的错误,这里表示Package Controll插件安装失败。解决方法是点击如图内容:

一步一步解决Mac os下Sublime Text 3中的中文显示乱码问题

在打开的窗口中添加:

"channels":
    [
        "/usr/local/channel_v3.json"
    ]

一步一步解决Mac os下Sublime Text 3中的中文显示乱码问题

        "channels"的路径为channel_v3.json在你电脑上的目录。设置完之后再去点击Install Packages的时候就可以正常的安装插件了。channel_v3.json文件也挂在这里。链接:https://pan.baidu.com/s/13ZFXrWlPL7KGQV9_4k6iXg  密码:wdtf。

        弄好了Packages Controll之后就可以安装支持中文格式的包了。打开Packages Controll然后输入Install Package,之后再分别输入“ConvertToUTF8”和”Codecs33“,分别安装ConvertToUTF8和Codecs33。如果自动安装不成功的话,就又需要手动安装。把下载好的ConvertToUTF8和Codecs33包都放进Sublime Text 的 Packages 文件夹下,重启就可以了,之后中文乱码的问题就解决了。

ConvertToUTF8下载:链接:https://pan.baidu.com/s/17Flh9ie87_jVKGvwIfQxsA  密码:66bn

Codecs33下载:链接:https://pan.baidu.com/s/1n_brKDRiK56yvxGPLKVemQ  密码:ptux

 

参考:https://github.com/SuCicada/channel_v3.json

https://blog.csdn.net/zknxx/article/details/52685094

https://github.com/seanliang/Codecs33/tree/osx

https://github.com/seanliang/Codecs33/blob/master/README.zh_CN.md

 

相关文章: