1. 程式人生 > >設定Eclipse中的tab鍵為4個空格的完整方法

設定Eclipse中的tab鍵為4個空格的完整方法

1.點選 window->preference-,依次選擇 General->Editors->Text Editors,選中右側的 insert space for tabs;如下圖所示,儲存,第一步完成;

2.點選 window->preference-,依次選擇 java(或C++)->code style ->formatter,點選右側的editor,選則左側 tab policy的值為spaces only,確定,應用儲存即可,如下圖所示:

若出現應用Apply按鈕為灰色的情況,需要回到上一步,點選new按鈕,根據當前的樣式重新生成一個新的樣式並儲存,重複第2步,編輯該樣式即可,如下圖:

eclipse code format設定

上面僅僅是針對Eclipse基本的Editor設定。對於Java/HTML/Ant等擴充套件編輯器,你還不得不單獨去設定
      * Preference:
       1). For Java: sets java code style in eclipse
           windows->preferences->java->Code style->Formatter
           add a new profile , for more detail, test it in eclipse

please
       2). For Ant: sets build.xml in eclipse
           windows->preferences->Ant>Editor->Formatter
           uncheck [Use tab character instead of spaces] option.
       3). For Html:
           windows->preferences->Web and XML->HTML Files->HTML Source
           select "Indent using tabs" and set space =2
       4). For XML
:
           windows->preferences->Web and XML->XML Files->XML Source
           select "Indent using tabs" and set space =2
       5). For Properties
    3). 如何配置jsp,properties等檔案預設使用UTF-8編碼建立或者閱讀?
     (Eclipse3.2+) Windows->General->Content Types下選擇指定的副檔名,然後說明相應的編碼,然後Update.
    4). 轉換存在檔案的回車換行格式

我在xml中遇到這種問題,我改到的地方只是在windows->preferences->myeclipse->files and editors->xml->xml source 下面的formatting欄中將line width 設定成172 ,預設是72.

我想,可能是因為line width 過小,導至在fomat時自動把xml 標籤split掉,然後又加了一些多餘的空格,因而改變了xml 實際內容。