iT邦幫忙

0

程式碼自動縮排的優化?

  • 分享至 

  • xImage

想問一下我是使用 Atom 編輯器
https://imgur.com/QIsQbke

原本程式碼都是兩個字元
https://imgur.com/mLKc1t9
如何讓他全部變成四個字元?
https://imgur.com/tGH2Ar5

只是原本所有的程式碼都是兩個字元⋯⋯
怎麼樣的方式可以一次原本兩字元取代成四個字元?
不然要一個一個去調整,程式碼有點多!
或是網上其他服務可以做到?

也就是原本如果是四字元的變成八字元
原本二字元變四字元,原本六字元變十二字元,以此類推⋯⋯(不是全部變四字元)

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
2
ccutmis
iT邦高手 2 級 ‧ 2019-10-10 01:26:47
最佳解答

安裝 atom-beautify 套件
( 官方說明 https://atom.io/packages/atom-beautify )

https://ithelp.ithome.com.tw/upload/images/20191010/20028574RoRd0YExkR.png

假設我們的程式碼長這樣
https://ithelp.ithome.com.tw/upload/images/20191010/20028574mzgM0b476Z.png

https://ithelp.ithome.com.tw/upload/images/20191010/20028574JKkjLYZ80L.png

完成結果為
https://ithelp.ithome.com.tw/upload/images/20191010/200285746uXhBg87Cr.png


另外這個設定好以後新寫的程式縮排都會是四個空格,就不用再處理上面的事了...

點主選單 File > Settings 開啟 Settings面板,
然後切到 Editor 分頁,在裡面可以找到你說的那個空格設定,預設值是2
同一頁裡面的的 Show Invisibles 建議也把它打勾。

https://ithelp.ithome.com.tw/upload/images/20191010/20028574Av57fg0vsU.png

看更多先前的回應...收起先前的回應...
ccutmis iT邦高手 2 級 ‧ 2019-10-10 08:56:08 檢舉

更新 : 安裝 atom-beautify 套件可以解決樓主的問題

火爆浪子 iT邦研究生 1 級 ‧ 2019-10-10 10:35:38 檢舉

他會吐
「Could not find 'php-cs-fixer'. The program may not be installed.

See php-cs-fixer installation instructions at https://github.com/Glavin001/atom-beautify#beautifiers or go to https://github.com/FriendsOfPHP/PHP-CS-Fixer
Your program is properly installed if running 'which php-cs-fixer' in your Terminal returns an absolute path to the executable.」
但我已經有裝 php-cs-fixer 了@@

ccutmis iT邦高手 2 級 ‧ 2019-10-10 11:40:17 檢舉

那個錯誤好像是因為它自動辦識的問題
可以試試

Edit > Select Grammer

然後在搜尋框打 HTML
點選 HTML (text.html.basic)
然後再重試一次

Packages > Atom Beautify > Beautify

我這邊測試是ok的
ps.我在Select Grammer那裡有試過選 PHP 但一樣會報錯,改選HTML後就ok了。

火爆浪子 iT邦研究生 1 級 ‧ 2019-10-10 11:53:19 檢舉

嗯我的PHP就會報錯

ccutmis iT邦高手 2 級 ‧ 2019-10-10 12:12:39 檢舉

真的還是不行就找別的 Beautify 套件或是換編輯器了._.
visual studio code不錯

火爆浪子 iT邦研究生 1 級 ‧ 2019-10-10 12:22:01 檢舉

網路上是有解法,只是我照做還是失敗

ccutmis iT邦高手 2 級 ‧ 2019-10-10 12:31:17 檢舉

這個可以參考一下
VSCode安裝與基本設定(他有示範套件安裝Beautify)
https://www.youtube.com/watch?v=D3CDmRjPdcE
接著要再安裝 PHP Intelephense(不要用php cs fixer一樣會報錯)

然後參考下面的操作就能在VSCode裡自動格式化php了,我剛試過沒問題
https://matthung0807.blogspot.com/2019/07/visual-studio-code-html-css.html

現在用visual studio code的人口愈來愈多了,樓主可以參考一下。

火爆浪子 iT邦研究生 1 級 ‧ 2019-10-10 13:09:50 檢舉

OKK

我也是用CODE,只要打開某個格式的檔案(如CPP或PHP),依畫面提示安裝該格式的支援Intelephense,就能直接按 ALT + CTRL + F 直接進行全部自動格式化

0
阿瑜
iT邦研究生 4 級 ‧ 2019-10-10 00:36:23

全選 Ctr + A , TAB 鍵

火爆浪子 iT邦研究生 1 級 ‧ 2019-10-10 01:10:08 檢舉


這樣都往前了⋯⋯原本沒有TAB就不用TAB!

0
ktutik
iT邦見習生 ‧ 2020-07-22 19:49:25

You can also use https://yamlonline.com/ for the yaml validator as well as yaml converter to json,csv,xml,base64 also for beautify and minify YAML.

我要發表回答

立即登入回答