NetBeans 能否在保存时删除尾随空格并将制表符更改为空格? [英] Can NetBeans remove trailing whitespace and change tabs to spaces on save?

查看:109
本文介绍了NetBeans 能否在保存时删除尾随空格并将制表符更改为空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 NetBeans,并且正在努力研究如何:

I just started to use NetBeans, and am trying to work out how to:

  1. 设置为在保存时删除尾随空格.我知道您可以手动调用它,但是如果您忘记了它会很烦人.可以在保存时自动完成吗?我希望这样做是因为它使代码保持整洁,因为当您在代码中移动并且文本光标到处都是因为您看不到尾随空格时,这真的很烦人,并且因为尾随空格对 HTML 有意想不到的影响布局和其他东西.

  1. Make it so that trailing whitespace is removed on save. I know that you can invoke it manually, but it’s annoying if you forget. Can it be done automatically on save? I want this done because it keeps the code neat, because it’s really annoying when you’re moving through code and the text cursor goes all over the place because of trailing whitespace you don’t see, and because trailing whitespace has unintended effects on HTML layouts and other stuff.

设置为在您键入时自动将制表符分成 4 个空格,而不是在保存时转换,或者更糟的是,仅在手动调用时进行转换.

Make it so that tabs are automatically made into 4 spaces while you’re typing rather than converting on save, or, worse, only when manually invoked.

推荐答案

[Original] 对于您的第一个问题,如何设置 NetBeans 以删除尾随空格,答案是没有设置(目前)来控制它.它自动发生,但不是每一行.空格只会从您编辑的行中删除(如果手动调用,则从整个文件中删除).有关更完整的说明,请参阅 Petr Pisl 的博客文章,标题为删除尾随空格".(请注意,即使他在博客中介绍 NetBeans 的 PHP 功能,此特定功能也适用于所有 NetBeans 支持的语言共享的基本编辑器.)

[Original] For your first question, how to set NetBeans to remove trailing whitespace, the answer is that there is no setting (at the moment) to control that. It happens automatically, but not to every line. Whitespace is only removed from the lines you edit (or from the entire file if invoked manually). See Petr Pisl's blog entry titled "Removing trailing spaces" for a more complete explaination. (Note that even though he is blogging about NetBeans' PHP features, this particular feature applies to the basic editor shared by all NetBeans supported languages.)

[更新]正如其他人在下面的评论和回答中指出的那样,此功能从 7.0 版开始可用.

[Update] This feature has been made available as of version 7.0, as pointed out by others in comments and answers below.

对于您的第二个问题,将编辑器设置为在您键入时自动将制表符转换为空格,您可以在编辑器格式选项中找到该设置:

For your second question, set the editor to automatically make tabs into spaces as you type, you can find that setting in the Editor Formatting options:

  1. 点击工具菜单,然后选择选项
  2. 点击顶部图标行中的编辑器
  3. 点击格式标签
  4. 语言字段中,确保选择了所有语言
  5. 类别字段中,确保选择了标签和缩进
  6. 选中将标签扩展到空格
  7. 对于 Language 字段中可用的每种其他语言,请检查是否未选中覆盖全局选项,或者将选项卡扩展到空格em> 也会检查该语言.
  8. 点击确定
  1. Click on the Tools menu, and choose Options
  2. Click on Editor in the top row of icons
  3. Click on the Formatting tab
  4. In the Language field, ensure that All Languages is selected
  5. In the Category field, ensure that Tabs And Indents is selected
  6. Check the box for Expand Tabs to Spaces
  7. For each additional language that is available in the Language field, check that either Override Global Options is not checked, or that Expand Tabs to Spaces is also checked for that language.
  8. Click OK

这将确保当您按制表键时插入指定数量的空格而不是制表符.与上面删除空格一样,文件中的任何现有选项卡都保持原样,除非您调用手动命令来更改整个文件.(此外,即使您编辑带有制表符的行——将制表符留在原处——编辑器也不会将它们转换为空格.此选项仅控制按下 TAB 键的新实例.)

That will make sure that when you hit the tab key the specified number of spaces is inserted rather than a tab character. As above with whitespace removal, any existing tabs in the file are left as-is unless you invoke the manual command to change the entire file. (Moreover, even if you edit a line with tabs on it--leaving the tabs in place--the editor will not convert them to spaces. Only new instances of hitting the TAB key are controlled by this option.)

这篇关于NetBeans 能否在保存时删除尾随空格并将制表符更改为空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆