Can NetBeans remove trailing whitespace and change tabs to spaces on save?

后端 未结 5 2102
渐次进展
渐次进展 2021-02-01 00:49

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

  1. Make it so that trailing whitespace is removed on save. I know that you can invoke it manually

相关标签:
5条回答
  • 2021-02-01 00:59

    [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.)

    [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. 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

    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.)

    0 讨论(0)
  • 2021-02-01 01:11

    Tools > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only

    This is as of Netbeans 7.3, according to Webmut.

    0 讨论(0)
  • 2021-02-01 01:14

    if you want to remove all trailing spaces in the file manually ONLY ONCE, you can invoke action 'Remove Trailing Spaces' from Source menu manually.

    Source -> Remove Trailing Spaces

    0 讨论(0)
  • 2021-02-01 01:16

    For the first question, NetBeans 7.0+ has now a built-in solution. You can find it in:

    On NetBeans 7:

    Tools > Options > Editor > General > When saving files > Remove Trailing Whitespace: Never / Always / For Modified Lines Only

    On NetBeans 8 / 9:

    Tools > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only

    0 讨论(0)
  • 2021-02-01 01:23

    For netbeans 7.4+

    Windows - Tools > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only

    Mac - Netbeans > preferences > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only

    Also you can set this as language specific. You can also set reformat while saving.

    0 讨论(0)
提交回复
热议问题