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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章