ubuntu16.04下sublime text3安装和配置
1.安装方法
1)使用ppa安装
sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer
卸载 sublime text 命令:
sudo apt-get remove sublime-text-installer
2)使用deb包安装
下载地址形如: https://download.sublimetext.com/files/sublime-text_build-版本号_amd64.deb
3126的下载地址为:https://download.sublimetext.com/files/sublime-text_build-3126_amd64.deb
不过貌似必须FQ才能下载
例如:
sudo dpkg -i sublime-text_build-3126_amd64.deb
3) 通过apt安装[网络不稳定,可能需要多次尝试]
参考: http://www.sublimetext.com/docs/3/linux_repositories.html#apt
安装GPG key:
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
确保apt能够使用https源
sudo apt-get install apt-transport-https
使用稳定版源
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
更新apt源并安装sublime-text
sudo apt-get update sudo apt-get install sublime-text
2. 打开命令
subl
3.在Help里输入license key(license key可以网上自己搜索)
—– BEGIN LICENSE —– Michael Barnes Single User License EA7E-821385 8A353C41 872A0D5C DF9B2950 AFF6F667 C458EA6D 8EA3C286 98D1D650 131A97AB AA919AEC EF20E143 B361B1E7 4C8B7F04 B085E65E 2F5F5360 8489D422 FB8FC1AA 93F6323C FD7F7544 3F39C318 D95E6480 FCCC7561 8A4A1741 68FA4223 ADCEDE07 200C25BE DBBC4855 C4CFB774 C5EC138C 0FEC1CEF D9DCECEC D3A5DAD1 01316C36 —— END LICENSE ——
4.安装Packeage Control
可参考: https://packagecontrol.io/installation
在终端输入subl打开sublime text3, 使用快捷键ctrl + `(ESC下面的键),在弹出的控制台中输出以下代码:
import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e3d39e33b79698005270310898eea76'; 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)
5.重启软件后可以在Preference菜单下找到Package Control命令
单击运行Packeage Control,搜索Install Package并进入该选项,此时即可为Sublime Text 3安装所需插件
6.关闭自动更新
Preferences -> Settings-User,在{}输入 ,"update_check":false
7.设置一个tab键对应4个空格
Preferences -> Settings-User,在{}输入
"tab_size": 4, "translate_tabs_to_spaces": true
8.解决中文无法输入问题
git clone https://github.com/lyfeyaj/sublime-text-imfix.git cd sublime-text-imfix/ sudo cp lib/libsublime-imfix.so /opt/sublime_text/ sudo cp src/subl /usr/bin/
关闭sublime的所有窗口,然后在终端输入subl,此时就可以输入中文了
hupeng@hupeng-vm:~$ which subl /usr/bin/subl hupeng@hupeng-vm:~$ cat /usr/bin/subl #查看一下subl命令做了什么 #!/bin/sh export LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text "$@"hupeng@hupeng-vm:~$
最终解决方法:
sudo vi /usr/share/applications/sublime_text.desktop #修改三个Exec Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text %F" Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text -n" Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /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=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=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;
遇到的问题: 将图标锁定到左侧任务栏后,再从任务栏启动后还是无法输入中文,而且图标显示untitled SublimeText(UNREGISTERED)
此外在搜索框中搜索会发现
显然左侧的图标不应该存在,因为已经成功注册。
解决方法:
反复尝试后发现在多次重装后产生了缓存的.desktop文件。只要将其删除即可。
# 查找相关的文件
find / -name sublime*
# 意外发现如下的.desktop文件
~/.local/share/applications/sublime_text.desktop
~/.local/share/applications/_opt_sublime_text_sublime_text.desktop
# 内容如下:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=untitled - Sublime Text (UNREGISTERED)
Icon=sublime_text.png
Path=/
Exec=/home/hupeng/Desktop/sublime_text_3/sublime_text
StartupNotify=false
StartupWMClass=Sublime_text
OnlyShowIn=Unity;
X-UnityGenerated=true
效果:
彻底卸载sublime-text
sudo apt-get remove --purge sublime-text
sudo apt-get autoremove
# 删除配置文件
sudo rm -rf /opt/sublime_text/
rm -rf ~/.config/sublime-text-3/
# 查找相关文件并手动删除
sudo find / -name sublime*
sudo updatedb
locate sublime-text
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true"> <use xlink:href="#csdnc-thumbsup"></use> </svg><span class="name">点赞</span> <span class="count">1</span> </a></li> <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-Collection-G"></use> </svg><span class="name">收藏</span></a></li> <li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{"mod":"1582594662_002"}"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-fenxiang"></use> </svg>分享</a></li> <!--打赏开始--> <!--打赏结束--> <li class="tool-item tool-more"> <a> <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg> </a> <ul class="more-box"> <li class="item"><a class="article-report">文章举报</a></li> </ul> </li> </ul> </div> </div> <div class="person-messagebox"> <div class="left-message"><a href="https://blog.csdn.net/zhengqijun_"> <img src="https://profile.csdnimg.cn/1/1/1/3_zhengqijun_" class="avatar_pic" username="zhengqijun_"> <img src="https://g.csdnimg.cn/static/user-reg-year/1x/4.png" class="user-years"> </a></div> <div class="middle-message"> <div class="title"><span class="tit"><a href="https://blog.csdn.net/zhengqijun_" data-report-click="{"mod":"popu_379"}" target="_blank">zhengqijun_</a></span> </div> <div class="text"><span>发布了170 篇原创文章</span> · <span>获赞 448</span> · <span>访问量 123万+</span></div> </div> <div class="right-message"> <a href="https://bbs.csdn.net/topics/395534107" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-messageboard">他的留言板 </a> <a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a> </div> </div> </div> </article>