linux下代碼格式化工具:indent

來源:互聯網
上載者:User

linux下代碼格式化工具:indent

ubuntu 下:$ sudo apt-get install indent

常用的設定:

indent -npro -kr -i4 -ts4 -sob -l80 -ss -bl -bli 0 檔案名稱

參數說明:
-npro或--ignore-profile  不要讀取indent的設定檔.indent.pro。
-kr  指定使用Kernighan&Ritchie的格式。可以換為 -orig,BSD風格
-i4  --indent-level 設定縮排的格數為4。
-ts4 設定tab的長度
-sob或--swallow-optional-blank-lines  刪除多餘的空白行。
-l80 代碼超過80換行
-ss或--space-special-semicolon  若for區段只有一行時,在分號前加上空格。
-ncs或--no-space-after-casts  不要在cast之後空一格。
-bl {分行顯示
-bli 0 括弧縮排為0

注意: 

<1>  -i4 -ts4同時設定

-i4 設定縮排多少字元,如果為tab的整數倍,用tab來縮排,否則用空格填充。

-i4 -ts4並不能就按照4個空格縮排,而是按一個tab。

當使用vim查看代碼時,

只有在.vimrc中設定 set ts=4

代碼才會按4個空格縮排。

<2> fileformats=unix, dos

在vim命令模式下,輸入“:set ffs”,得到:  fileformats=unix,dos
所以vim同時支援 unix和dos格式(不同的行結束符)

輸入“:set ff”,可以得到當前檔案格式。

如果需要轉換的檔案的格式是dos的,在使用indent轉換後會多出很多^M。

解決辦法:

:set ff=unix

:wq

$ indent ...

這樣就可以了。
參考:

http://hi.baidu.com/houhou1999/blog/item/4983d41b680825c5ac6e75cd.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.