【发布时间】:2017-07-31 09:44:06
【问题描述】:
在创建了许多文件之后,我将 Eclipse 配置更改为 use spaces instead of tabs。它有效:我写的新东西使用空格。但是我昨天写的文件当然还有标签。我想将它们从制表符转换为空格。
对于 Java 文件很简单:打开文件,按 CTRL+a,按 CTRL+i,完成。
但是对于 XML 文件该怎么做呢?与 Java 不同,对于 XML 文件,CTRL+a/CTRL+i 不仅可以转换制表符,还可以尝试“改进格式”,这会破坏事情:
初始代码:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans>
<bean id="webscript.helloworld.get"
class="com.example.HelloWorldWebScript"
parent="webscript">
</bean>
</beans>
在 CTRL+a/CTRL+i(或 CTRL+SHIFT+f)之后:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
You under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<beans>
<bean id="webscript.helloworld.get" class="com.example.HelloWorldWebScript"
parent="webscript">
</bean>
</beans>
问题:对于Eclipse中的一个XML文件,如何将制表符转换为空格,不做其他改动?
【问题讨论】:
-
暂时无法检查,这是一个旧帖子,所以不确定这是否仍然有效,但 Format XML code in Eclipse 或更手动的解决方案 eclipse xml editor indent using spaces
-
@AxelH:不重复。 stackoverflow.com/questions/31747059/… 询问如何更改设置,我已经完成了。 stackoverflow.com/q/4527474/4391450 只有 Ctrl+Shift+F 答案,并且如您所知,Ctrl+Shift+F 会破坏所有格式(只需尝试上面的示例代码)。请重新阅读我的问题:我已经将 Eclipse 设置为使用空格而不是制表符,并且我想要一个仅修复间距而不进行任何其他格式化的命令。
-
我的错,误读了您使用的快捷方式。我看到两个解决方案,使用脚本或尝试在 Eclipse 中创建新格式,这只会编辑选项卡,禁用其他所有内容。我无法测试,因为不幸的是办公室不使用 eclipse,所以不确定是否可以禁用每个格式选项。您在示例中的问题是列长度属性,设置一个巨大的值来修复它