eclipse基本設置----中文亂碼、行數顯示、縮進方式、行末空格和空行自動刪除、常用註解
一、中文亂碼
window系統下,Eclipse中導入新的項目的時候,可能會遇到中文亂碼的問題。
解決方案:將系統默認的格式為GBK改成UTF-8。以下是具體解決方法,可以根據需要選擇不同的方法。
1、設置整個工作空間的編碼,此操作會影響整個工作空間的項目。
設置步驟:菜單欄window -- Preferences -- General -- Workspace --Text file encoding--Other --UTF-8,保存配置(Apply and Close)。
2、設置項目的編碼,此操作只影響被選中項目。
設置步驟:選中項目右鍵 -- Properties -- Resource --Text file encoding--Other --UTF-8,保存設置。
3、設置單個文件的編碼,此操作只影響被選中文件。
設置步驟:選中文件右鍵 -- Properties -- Resource --Text file encoding--Other --UTF-8,保存設置。
二、eclipse中顯示代碼行數、空格(space)和制表符(tab)
未設置前:
設置步驟: 菜單欄Window -- Preferences -- Gerenal -- Editors -- Text Editors,保存設置。
(顯示行數也可以直接用Ctrl+F10, 然後勾選Show Line Numbers)
設置後:
三、設置縮進方式(一個tab為四個空格)
設置步驟:
1)、設置縮進:菜單欄Window -- Preferences -- Gerenal -- Editors -- Text Editors--Insert spaces for tabs,保存設置;
2)、將tab為4個空格配置到formatter中:
i)、菜單欄Window -- Preferences -- Java -- Code Style -- Formatter;
ii)、新建一個文件,配置如下所示,保存;
iii)、Source -- Format,進行格式化。
四、保存時自動刪除行末空格以及空行(現象是左圖到右圖)
設置步驟:Window -- Preferences -- Java -- Editor -- Save Action -- Perform the ... -- Additional actions -- Configure... -- Remove trailing whitespace -- All lines
五、常用註解
設置步驟:菜單欄Window -- Preferences -- Java -- Code Style --Code Templates -- Comments
1、Files -- Edit
/**
* @Description:
* @Package ${package_name}
* @Title: ${file_name}
* @author sucb
* @date ${date}
*/
Files
2 、Types -- Edit
/**@Description:
* @Package ${package_name}
* @Title: ${file_name}
* @author sucb
* @date ${date}
*/
Types
3、Methods -- Edit
/**
* ${tags}
* @author sucb
* @date ${date}
*/
View Code
eclipse基本設置----中文亂碼、行數顯示、縮進方式、行末空格和空行自動刪除、常用註解