使用Idea给项目的pom.xml添加依赖或配置xml时,发现在xml里使用代码补全或者粘贴代码时,xml里代码没有自动缩进,并且使用Alt+Shift+L也没有格式化成功
- 代码补全
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
</dependency>
- 粘贴代码
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
之前也看了很多别人的解决方法,但是并没有解决问题,经过自己的琢磨后成功解决(可能是版本或者其他的原因)我的idea2020版本格式正常了
1.Setting --> Edior --> Code Style --> XML
点开之后,点击Other选项,找到下面的Keep white spaces
我的默认是勾选的,别人是勾选格式就正常了,但是我是不勾选才正常,你可以试试看看效果
- 代码补全
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
</dependency>
- 粘贴代码
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
2.Setting --> Edior --> General --> Smart Keys
如果还是没有效果可以试试这个,我用的是Indent each line(缩进每行),还不行试试另外几个选项