【筆記】CentOS安裝Sublime Text 3

CentOS安裝Sublime Text 3

1) 安裝ST3

# 建個目錄
mkdir -p /opt/Backup
cd /opt/Backup

# 下載相應的tarball: http://www.sublimetext.com/3
wget http://[st3.tar.bz2]
tar jxvf [st3.tar.bz2]
mv sublime_text_3 /opt/sublime_text  # 放到/opt下

# 創建軟連接,以方便終端打開
ln -s /opt/sublime_text/sublime_text /usr/bin/sublime
# 創建桌面快捷
cp /opt/sublime_text/sublime_text.desktop /usr/share/applications
cd /usr/share/applications
vi sublime_text.desktop
# 更改"Icon=/opt/sublime_text/Icon/48x48/sublime-text.png"
# 而後,於"Applications > Programming > Sublime Text"右鍵"Add this launcher to desktop"

ps: 一開始沒注意,下載的是deb包。須要安裝alien將deb轉爲rpm再安裝。(可忽略,直接跳到第2節)python

# 安裝alien: http://ftp.de.debian.org/debian/pool/main/a/alien/
wget http://ftp.de.debian.org/debian/pool/main/a/alien/alien_8.90.tar.gz
tar zxvf alien_8.90.tar.gz
cd alien
perl Makefile.PL  # 可能會遇到"Issue 1"
make
make install

# deb轉爲rpm
cd ..
alien -r [st3.deb]  # 可能會遇到"Issue 2"
# 安裝rpm包
rpm -ivh [st3.rpm]

"Issue 1": Can't locate ExtUtils/MakeMaker.pm in @INC...linux

yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker -y

"Issue 2": no entry data.tar.gz in archive ... Error executing "ar -p ...git

# 未解決~

參考github

  1. Centos下安裝Sublime
  2. Sublime Text 2 for Linux 的安裝、配置彙總

2) 基本插件

2.1) Package Control:包管理器windows

"ctrl+`"調出控制檯,輸入標題連接內提供的Code,回車運行便可。於菜單欄"Preferences"下可看到"Package Control"。sublime-text

而後,經過它的"Install Package"安裝其餘插件。markdown

2.2) SideBarEnhancements:側邊欄右鍵操做加強app

Preferences > Key Bindings - User,添加快捷:sublime-text-3

{ "keys": ["ctrl+t"], "command": "side_bar_new_file2" },
{ "keys": ["f2"], "command": "side_bar_rename" },

2.3) ConvertToUTF8:其餘編碼支持ide

有個注意事項:

Linux 用戶:Sublime Text 2 和 3 內嵌 Python 版本中缺失幾個 ConvertToUTF8 依賴的動態庫。您必須手工安裝這些文件才能讓本插件徹底運做。

2.4) SublimeLinter:檢查語法錯誤

好多,選本身要用的語言,如Python的"SublimeLinter-pep8"。

2.5) SublimeCodeIntel:代碼提示

安裝完成後,會提示你:

For Linux:
  * Jump to definition = ``Super+Click``
  * Jump to definition = ``Control+Super+Alt+Up``
  * Go back = ``Control+Super+Alt+Left``
  * Manual CodeIntel = ``Control+Shift+space``

C系列語言的話,用SublimeClang

2.6) Markdown Preview:Markdown預覽

設置快捷"ctrl+m+p":

{ "keys": ["ctrl+m", "ctrl+p"], "command": "markdown_preview", "args": {"target": "browser", "parser":"markdown"} },

2.7) InputHelper:輸入幫助

Sublime輸入不了中文,首先安裝中文字體:

# 下載"YaHei.Consolas.1.12.Revise.ttf"字體
mkdir -p /usr/share/fonts/truetype/
# 將下載的字體拷貝到上述目錄
fc-cache /usr/share/fonts/truetype

# 配置爲該字體,見第3節"font_face"

而後安裝InputHelper,重啓Sublime。以後"Ctrl+Shift+Z",調出對話框,切換輸入法,便可輸入中文。

若是很不幸沒效果的話,能夠參考下最後附錄:InputHelper插件問題。

3) 基本設置

Preferences > Settings - User,添加Tab空格及顯示:

"draw_white_space": "all",
"tab_size": 4,
"translate_tabs_to_spaces": true,
"font_face": "YaHei Consolas Hybrid",

4) 參考

略。


附錄:InputHelper插件問題,"Ctrl+Shift+Z"調不出對話框,解決手順。

Step 1: "Ctrl+`"調控制檯,"Ctrl+Shift+Z"看輸出:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "inputhelper in /home/join/.config/sublime-text-3/Installed Packages/InputHelper.sublime-package", line 21, in run
  File "X/subprocess.py", line 818, in __init__
  File "X/subprocess.py", line 1416, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: '/home/join/.config/sublime-text-3/Packages/InputHelper/lib/linux_text_input_gui.py'

Step 2: 解壓"Installed Packages/"下"InputHelper.sublime-package"到"Packages/",並刪除原包,重啓Sublime。以直接用源代碼。

Step 3: "Ctrl+Shift+Z"再看輸出:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "/home/join/.config/sublime-text-3/Packages/InputHelper/inputhelper.py", line 21, in run
    proc = subprocess.Popen(args, stdout=subprocess.PIPE)
  File "X/subprocess.py", line 818, in __init__
  File "X/subprocess.py", line 1416, in _execute_child
PermissionError: [Errno 13] Permission denied

Step 4: 修改"inputhelper.py"添加輸出,看Popen了什麼。爲"InputHelper/lib/linux_text_input_gui.py"。繼而查看其權限爲"-rw-rw-r--",以下直接改成777:

chmod 777 /home/join/.config/sublime-text-3/Packages/InputHelper/lib/linux_text_input_gui.py

Step 5: 繼續"Ctrl+Shift+Z",沒效果。直接運行"linux_text_input_gui.py",發現:

ImportError: No module named pygtk

Step 6: "pip install PyGTK"安裝pygtk,但:

CompressionError: bz2 module is not available

Step 7: 源於編譯Python2.7時沒bz2模塊,make時會提示缺失"bz2"。編譯前安裝有bzip2便可:

# 須要bzip2,不論如何,執行下行命令
yum install bzip2 bzip2-devel -y

重編譯安裝,見CentOS升級Python2.7及安裝pip

Step 8: 從新"pip install PyGTK",而後:

Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/PyGTK
Storing debug log for failure in /root/.pip/pip.log

# 直接從源碼安裝
wget http://pypi.douban.com/packages/source/P/PyGTK/pygtk-2.24.0.tar.bz2
tar jxvf pygtk-2.24.0.tar.bz2
cd pygtk-2.24.0
python setup.py install
# 同樣提示錯誤:
# ********************************************************************
# * Building PyGTK using distutils is only supported on windows. *
# * To build PyGTK in a supported way, read the INSTALL file.    *
# ********************************************************************
vi INSTALL
# 看來要重編
./configure

# issue: configure: error: Package requirements (pygobject-2.0 >= 2.21.3) were not met: ... No package 'pygobject-2.0' found ...
# 缺乏pygobject
# yum list pygobject*
yum install pygobject2 pygobject2-devel -y
# issue: configure: error: Package requirements (pygobject-2.0 >= 2.21.3) were not met:
# Requested 'pygobject-2.0 >= 2.21.3' but version of PyGObject is 2.20.0
# pygobject版本不夠
rpm -e pygobject2-devel

# 下個高版本的PyGObject
wget http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.10/pygobject-3.10.2.tar.xz
tar Jxvf pygobject-3.10.2.tar.xz
cd pygobject-3.10.2

Step 9: 感受很折騰,應該是因爲目前爲Python2.7才依賴了高版本的PyGObject,因此:

# 而原先Python2.6還裝着,因此:
vi /home/join/.config/sublime-text-3/Packages/InputHelper/lib/linux_text_input_gui.py
# 把第一行改成"#!/usr/bin/env python2.6.6"
# 而後"Ctrl+Shift+Z"果然彈出了對話框,但Sublime UI阻塞,未響應。

cd /home/join/.config/sublime-text-3/Packages/InputHelper/lib/
python2.6.6 linux_text_input_gui.py
# 輸入內容後回車,看到以下錯誤:
# AttributeError: 'gtk.Entry' object has no attribute 'get_buffer'
# Traceback (most recent call last):
#   File "linux_text_input_gui.py", line 14, in destroy
#     self.print_text()
#   File "linux_text_input_gui.py", line 9, in print_text
#     buffer = self.textInput.get_buffer()
# AttributeError: 'gtk.Entry' object has no attribute 'get_buffer'
# 給"linux_text_input_gui.py"的"SimpleTextInput::print_text()"添加打印,看"self.textInput"的屬性。直接有"get_text",因此作以下修改:
# def print_text(self):
#     # buffer = self.textInput.get_buffer()
#     # print(buffer.get_text())
#     print(self.textInput.get_text())
# 問題解決。pygtk版本不一樣的緣由麼?

Step 10: 折騰死我了,不想活了TT。

相關文章
相關標籤/搜索