Ubuntu安装SublimeText3并配置相关内容
下载安装SublimeText3
1.下载SublimeText3
的安装包,官网地址
2.解压安装包
3.解压获得 sublime_text_3
文件夹,将该文件夹重命名为sublime_text
4.点击右键,打开终端,输入下面代码,把文件夹移动到/opt/
sudo mv sublime_text /opt/
5.在/usr/bin/
下创建链接
sudo ln -s /opt/sublime_text/sublime_text /usr/bin/sublime
6.现在你在终端已经可以打开sublime text 3
sublime
7.当然为了方便我们需要建立一个图标链接
sudo sublime /usr/share/applications/sublime.desktop
把下面内容粘贴进去
[Desktop Entry]
Version=3.0
Type=Application
Name=sublime
GenericName=Text Editor
Comment=Sophisticated text editor for code, markup and prose
Exec=/opt/sublime_text/sublime_text %F
Terminal=false
MimeType=text/plain;
Icon=/opt/sublime_text/Icon/48x48/sublime_text.png
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;
[Desktop Action Window]
Name=New Window
Exec=/opt/sublime_text/sublime_text -n
OnlyShowIn=Unity;
[Desktop Action Document]
Name=New File
Exec=/opt/sublime_text/sublime_text --command new_file
OnlyShowIn=Unity;
SublimeText3无法输入中文的解决办法
1.下载我们需要的文件,打开终端,输入
git clone https://github.com/lyfeyaj/sublime-text-imfix.git
2.将下载的文件解压之后,移到当前目录(~目录下边),然后执行下边命令
cd ~/sublime-text-imfix (前提:解压后的sublime-text-imfix必须在~目录下)
sudo cp ./lib/libsublime-imfix.so /opt/sublime_text/
sudo cp ./src/subl /usr/bin/
这时候
/usr/bin
里有两个文件都可以打开SublimeText
,subl
和sublime
,但是用subl
打开可以输入中文,而sublime
打开不行,如果觉得不好的话,可以把sublime
删除掉
3.最后把sublime
都关掉,然后在终端输入subl
,就可以在sublime
使用中文了
这个时候,必须在终端输入
subl
启动SublimeText
才起作用的
4.如果想通过图标打开Sublime
也可以输入中文的话,解决办法如下
打开终端,输入以下代码
cat /usr/bin/subl #查看一下subl命令做了什么
export LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so
exec /opt/sublime_text/sublime_text "$@"hupeng@hupeng-vm:~$
注: export命令将变量导出,并使之在能在子shell中有效
最终,解决办法如下:
sudo vi /usr/share/applications/sublime_text.desktop
# 修改三个`Exec`,在前面加入`env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so`
Exec=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text %F
Exec=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text -n
Exec=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text --command new_file
修改完成后,/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=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /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=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text -n
OnlyShowIn=Unity;
[Desktop Action Document]
Name=New File
Exec=env LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text --command new_file
OnlyShowIn=Unity;
添加Python3 Build System
{
"cmd": ["/home/hp/anaconda3/envs/tensorflow/bin/python3","-u","$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"LANG": "en_US.UTF-8"}
}
报错问题
SublimeText Python3 UnicodeEncodeError
不能输出中文
出现这个错误是因为在SublimeText中构建语言的设置少了一个参数,添加上去就行了:"env": {"LANG": "en_US.UTF-8"}
{
"cmd": ["/home/hp/anaconda3/envs/tensorflow/bin/python3","-u","$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"LANG": "en_US.UTF-8"}
}