參考:java編程規范之eclipse設置tab鍵為四個空格
Eclipse版本

1、點擊菜單Window > Preference

2、在Preferences窗口中,展開General > Editors,選Text Editors,勾選Insert spaces for tabs,點擊Apply

3、在Preferences窗口中,展開Java > Code Style,選Formatter,點擊New...;在New Profile窗口中,填寫Profile name之后,點擊OK

4、在彈出的Profile '...'窗口中,展開Indentation,設置Tab policy: Spaces only,點擊OK

5、在Preferences窗口中,點擊Apply and Close。
以后,每當我們在代碼編輯器中按下Tab鍵,就會插入4個空格。

6、如果想顯示空格,可以在Preferences窗口中,展開General > Editors,選Text Editors,勾選Show whitespace characters (configure visibility)


