2014年10月23日 星期四

sublime 常見問題

在前端開發嘗試過許多編輯器,現在打算用sublime來開發前端,在這邊順便寫下我摸過的編輯器的優缺點
優點缺點
aptana1. 我最熟悉
2. bug較少
1. jQuery只支援到1.6版
2. 擴展麻煩(css3, snippet, AngularJS)
3. 肥大(雖然我不在意)
eclipse-PDT1. 套件多
2. jQuery支援版本較新
1. bug多
2. 設定繁雜、版本太多
3. 肥大
webstorm1. 功能強大、套件完整
2. jQuery支援版本較新
1. 需付費
2. 設定繁雜、熱鍵需重新熟悉
3. 肥大
sublime1. 較輕量
2. 列模式
3. 有AngularJS、jQuery擴展
1. 熱鍵、介面不熟悉
2. Install Package有時候連不上
其他:
vim - 太遮疼,手太殘
Netbeans, Atom, notepad++ - 研究不深

修正註解script tag的bug
sublime在 <script src="jquery.js"></script> 使用ctrl+ / 註解時會變成
// <script src="jquery.js"></script>
要如何把他變成
<!-- <script src="jquery.js"></script> -->
http://wesbos.com/fix-sublime-text-toggle-comment/
1. 找HTML.tmLanguage, preferences → browse packages → HTML,
2. 編輯HTML.tmLanguage:
在286行附近將
<string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)</string>
取代成
<string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)(?!.*&lt;/script&gt;)</string>
注意:
arch linux安裝sublime 3 ,用browse packages會開啟目錄
/home/bear/.config/sublime-text-3/Packages/
但HTML.tmLanguage位置在
/home/bear/.config/sublime-text-2/Packages/HTML/HTML.tmLanguage
用sublime修改sublime-text-2下的HTML.tmLanguage,然後存檔後就能修正這個bug
仍然有bug:
<script src="jquery.js"></script> 必須在貼近文件的最左邊(不能有縮排),才能正常註解。所以要先把<script>最前面的縮排先刪掉=> ctrl+/註解掉 => 再用自動縮排(HTML-CSS-JS Prettify)縮回來
HTML.tmLanguage位置在
/opt/sublime_text_3/Packages/HTML.sublime-package 這個壓縮檔裡面
將HTML.sublime-package複製成zip檔再用unzip解開,照上面方法修改HTML.tmLanguage後再用zip壓回放回原位置。重開sublime即可修復此bug
注意:
sublime的syntax設成handlebars時,仍然會有bug。要設回html
Windows 7 安裝版 ( 修正註解script tag的bug )
一樣找 HTML.sublime-package (位置在 C:\Program Files (x86)\Sublime Text 3\Packages )
方法同上,改成zip解開後改裡面的HTML.tmLanguage 再壓回去改回原本檔案名稱
參考資料:
http://stackoverflow.com/questions/19790062/where-to-put-tmlanguage-in-sublime-text-3


推薦的HTML縮排工具
http://stackoverflow.com/questions/8839753/how-do-i-reformat-html-code-using-sublime-text-2
套件我用HTML-CSS-JS Prettify
JS部份我用 jsFormat 縮排

修改tag的名字
"Rename Tag" action: Ctrl + Shift + '

PHP縮排美化工具
php.fmt (用package control裝就好)
https://github.com/phpfmt/sublime-phpfmt
設定檔( Preferences -> Package Settings -> phpfmt -> Setting - User ):
{
"php_bin":"C:/xampp/php/php.exe", // 注意:因為我沒裝php,要設xampp的php,不能設cygwin的php(可能是因為cygwin的php是基於linux的php)
"format_on_save":false,
"indent_with_space": 4,
"version": 1
}
熱鍵: ctrl+shfit+p 後搜尋 phpfmt

sublime text 3 phpfmt:format 出錯
解法:
http://windows.php.net/download/
下載 Non Thread Safe 的版本zip檔
解壓縮到C:/PHP7
Preferences -> Package Settings -> phpfmt -> Setting - User
"php_bin": "C:/PHP7/php.exe",

CodeFormatter (用package control裝就好)
https://github.com/akalongman/sublimetext-codeformatter
設定檔( Preferences -> Package Settings -> CodeFormatter -> Setting - User ):
{
"codeformatter_php_path": "C:/xampp/php/php.exe"  // 理由同上
}

按一次tab,出現兩次tab
http://stackoverflow.com/questions/24356939/sublime-text-3-double-tab-issue
重開sublime即可

tab中文出現亂碼
https://github.com/seanliang/ConvertToUTF8/issues/28
如圖:
解法:
Preferences => Settings => 新增 "dpi_scale": 1, =>重啟Sublime

F12 goto definition不作用
左下角顯示 unable to find xxx
解法:
Preferences => Key Bindings => 打開來後關掉
這時候ctrl + ` 的 sublime console會顯示錯誤:
Unable to open /D/bear/Sublime/Data/Packages/Default/Default (Windows).sublime-keymap
Traceback (most recent call last):
  File "D:\bear\Sublime\sublime_plugin.py", line 462, in run_callback
    expr()
  File "D:\bear\Sublime\sublime_plugin.py", line 603, in <lambda>
    run_callback('on_activated', callback, lambda: callback.on_activated(v))
  File "D:\bear\Sublime\Data\Installed Packages\TrailingSpaces.sublime-package\trailing_spaces.py", line 419, in on_activated
    self.freeze_last_version(view)
  File "D:\bear\Sublime\Data\Installed Packages\TrailingSpaces.sublime-package\trailing_spaces.py", line 440, in freeze_last_version
    on_disk = codecs.open(file_name, "r", "utf-8").read().splitlines()
  File "./python3.3/codecs.py", line 896, in open
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\bear\\Sublime\\Data\\Packages\\Default\\Default (Windows).sublime-keymap'
Could not import subprocess32 module, falling back to subprocess module
...
WINDOW COMMAND ENABLED False
然後這問題就解決了... F12可以用了

在Project => Quick Switch Project和Open Recent移除專案
https://forum.sublimetext.com/t/how-do-i-remove-a-project-from-the-switch-project-window/3725
關閉Sublime,使用其他編輯器,修改Sublime Data\Local目錄下的 Session.sublime_session 中的 "workspaces" => "recent_workspaces": ,直接刪除不要的Project,重啟Sublime

使用Alignment對齊你的Code(縮排)
http://kevintsengtw.blogspot.com/2012/03/sublime-text-2-part5-alignmentcode.html
快速鍵「Ctrl + Alt + a」

使用Alignment 對齊 php 靜態陣列:
    public static $status = [
        self::STATUS_RECEIVED   =>  '未支付',
        self::STATUS_SUCCESS    =>  '支付成功',
        self::STATUS_FAIL       =>  '支付失败',
        self::STATUS_SELECT_FAILED =>  '海选失败',
        self::STATUS_EXCEPTION  =>  '支付异常订单',
        self::STATUS_CLOSED     =>  '订单关闭',
        self::STATUS_DISPUTE     =>  '争议中'
    ];
以上陣列直接用Alignment對齊是不作用的,
https://github.com/wbond/sublime_alignment/issues/33
niquedegraaff: I can confirm. Alignment is not working at all in PHP for me. (Windows 7 64 bit)
解法:
複製黃色區塊到新的sublime 文件上 => 列模式刪除 self:: 改成$ => Aligment 熱鍵對齊 => 列模式將$改回 self:: => 貼回原本文件位置


git diff時換行出現^M,且不換行
https://stackoverflow.com/questions/11899843/fixing-sublime-text-2-line-endings
場景:某個加密文件貼回明文後報錯
看來原加密文件是格式Windows 1252。因為
http://violin-tao.blogspot.com/2016/05/crlflf-bug.html
CRLF 就是 \r\n 是只有在 windows 系統在用的形式
所有的 UNIX 系統都是用 \n
CR是carriage return的意思,也就是\r
LF是line feed的意思,也就是\n
這就是為什麼有些檔案從unix系統拿去windows上面看 會變成全部都在同一行
因為只有LF 他不知道是換行
windows只吃CRLF
除了一些比較聰明的文字編輯器會分的出來
解法:

使用sublime 打開該文件。View => Line Endings => 選Unix => 保存
這樣就能使該文件的結尾是\n,在Linux 上git diff 就不會出現^M了
ps.
我沒採用 git config --global core.autocrlf true 這種或類似對.gitconfig [core]增加配置的方法
https://stackoverflow.com/questions/1889559/git-diff-to-ignore-m

避免git diff -w 時出現 warning: CRLF will be replaced by LF in xxx 錯誤
如下:
$ git status
#       modified:   public/css/hipay.css
$ git diff -w
warning: CRLF will be replaced by LF in public/css/hipay.css.
The file will have its original line endings in your working directory.
https://stackoverflow.com/questions/17628305/windows-git-warning-lf-will-be-replaced-by-crlf-is-that-warning-tail-backwar/17628353
$ git config --global core.autocrlf false
reset 到最前面的的commit再pull
$ git reset --hard commit_id
$ git pull
$ git status
# On branch master
nothing to commit, working directory clean

installer重裝sublime 3 到同一個位置後忽然無法用package control 安裝package
sublime console報錯:
Package Control: Skipping automatic upgrade, last run at 2019-04-09 21:03:51, next run at 2019-04-09 22:03:51 or after
Traceback (most recent call last):
  File "C:\Users\48\AppData\Roaming\Sublime Text 3\Installed Packages\Package Control.sublime-package\package_control/package_installer.py", line 154, in on_done
  File "C:\Users\48\AppData\Roaming\Sublime Text 3\Installed Packages\Package Control.sublime-package\package_control/package_disabler.py", line 76, in disable_packages
ImportError: No module named 'package_control'
https://www.rrosetta.com/computers-programming/sublime-text-3-importerror-no-module-named-package_control#comment-13388
Preferences => Settings => 移除ignored_packages 的 "0_package_control_loader"







沒有留言:

張貼留言