设置Eclipse中的tab键为4个空格的完整方法

本文详细介绍了如何在Eclipse中进行编辑器的基本设置,包括替换制表符为空格、设置Java、HTML、Ant等文件的代码风格,以及如何配置文件的默认编码和回车换行格式。

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 实际内容。


在 STM32CubeIDE 中配置编辑器使用 4空格代替 Tab ,可以通过以下步骤完成。STM32CubeIDE 是基于 Eclipse 平台的开发环境,因此其配置方式与 Eclipse 类似。 ### 配置步骤 1. **打开 STM32CubeIDE** - 启动 IDE 并进入工作区。 2. **进入首选项设置** - 点击顶部菜单栏的 `Window`,然后选择 `Preferences`(或者直接使用快捷 `Ctrl + ,`)[^1]。 3. **配置 C/C++ 编辑器的缩进** - 在左侧导航树中展开 `C/C++` 节点,然后选择 `Code Style` -> `Formatter`。 - 点击 `Edit` 按钮,进入格式化配置界面。 - 在 `Indentation` 标签页下: - 设置 `Tab policy` 为 `Spaces only`。 - 设置 `Indentation size` 和 `Tab size` 均为 `4`。 - 点击 `OK` 保存设置并返回主设置界面[^1]。 4. **配置编辑器的常规设置** - 在左侧导航树中选择 `General` -> `Editors` -> `Text Editors`。 - 勾选 `Insert spaces for tabs`。 - 设置 `Displayed tab width` 为 `4`[^1]。 5. **保存并应用配置** - 点击 `Apply and Close` 以保存所有更改。 ### 示例代码格式化效果 ```c // 示例代码:GPIO初始化函数 void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); /*Configure GPIO pin : PA8 */ GPIO_InitStruct.Pin = GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } ``` 在完成上述配置后,编辑器将自动使用 4空格代替 Tab ,并在保存或格式化代码时保持一致的缩进风格。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值