Sublime text3 installation and configuration under ubuntu16.04

1. Installation method

1) Install using ppa

sudo add-apt-repository ppa:webupd8team/sublime-text-3

sudo apt-get update

sudo apt-get install sublime-text-installer

Uninstall sublime text command:

sudo apt-get remove sublime-text-installer


2) Install using deb package

The download address is like: https://download.sublimetext.com/files/sublime-text_build-version_amd64.deb

The download address of 3126 is: https://download.sublimetext.com/files/sublime-text_build-3126_amd64.deb

But it seems that FQ is required to download

E.g:

sudo dpkg -i sublime-text_build-3126_amd64.deb


3) Install via apt [unstable network, multiple attempts may be required]

Reference http://www.sublimetext.com/docs/3/linux_repositories.html#apt

Install GPG key:

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

Make sure apt is able to use https sources

sudo apt-get install apt-transport-https

Use stable source

echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Update apt sources and install sublime-text

sudo apt-get update
sudo apt-get install sublime-text


2. Open command

subl


3. Enter the license key in Help (the license key can be searched online by yourself)

copy code
—– 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 ——
copy code


4. Install Package Control

Reference:  https://packagecontrol.io/installation

Enter subl in the terminal to open sublime text3, use the shortcut key ctrl + ` (the key below ESC), and output the following code in the pop-up console:

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. After restarting the software, you can find the Package Control command under the Preference menu

Click Run Package Control, search for Install Package and enter this option, then you can install the required plugins for Sublime Text 3


6. Turn off automatic updates

Preferences -> Settings-User,在{}输入 ,"update_check":false

 


7. Set a tab key to correspond to 4 spaces

Preferences -> Settings-User, enter in {} 

"tab_size": 4,
"translate_tabs_to_spaces": true


8. Solve the problem that Chinese cannot be input

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/

Close all windows of sublime, then enter subl in the terminal, then you can enter Chinese

copy code
hupeng@hupeng-vm:~$ which subl
/usr/bin/subl
hupeng@hupeng -vm:~$ cat /usr/bin/    subl #See what the 
subl command does # !/bin/sh 
export LD_PRELOAD =/opt/sublime_text/ libsublime-imfix.so
 exec /opt/sublime_text/sublime_text " $@ " hupeng@hupeng-vm:~$
copy code

Final solution:

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"

The contents of /usr/share/applications/sublime_text.desktop are as follows:

copy code
[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;
copy code

 Problems encountered: After locking the icon to the left taskbar, it is still unable to input Chinese after starting from the taskbar, and the icon displays untitled SublimeText (UNREGISTERED)

Also, searching in the search box will find

Apparently the icon on the left should not be there because it has been successfully registered.

 

Solution: 

After repeated attempts, it was found that cached .desktop files were generated after multiple reinstalls. Just delete it.

 

copy code
# find related files
find  /  -name sublime*
#Accidentally found the following .desktop file 
~/.local/share/applications/ sublime_text.desktop
 ~/.local/share/applications/ _opt_sublime_text_sublime_text.desktop #The
 content is as follows: 
[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
copy code

 Effect:

Completely uninstall sublime-text

copy code
sudo apt-get remove --purge sublime-text
sudo apt-get autoremove

#Delete configuration file 
sudo rm -rf /opt/sublime_text/ rm 
-rf ~/.config/sublime-text-3/
 #Find related files and delete manually 
sudo find / -name sublime*

sudo updatedb
locate sublime-text


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325834792&siteId=291194637