Search code examples
phpnetbeansline-breakscode-formatting

Remove empty lines in Netbeans 7.x


Is there any plugin, macro or built-in function that can remove empty or redundant empty lines in Netbeans 7.2 (PHP bundle, Windows 7)? Due to different line-break formats in my upload and download process (Win <> Unix, via FileZilla and Netbeans), many PHP files doubled (even quadrupled) their line breaks.

Double line breaks in PHP file

I could remove them file by file using PSPad - but I am looking for an automatic or batch-capable solution. I can accept an external tool if available.

Edit: I know about the Source > Format helper, but there are no settings to remove blank lines.


Solution

  • You can do this with a regular expression + and a replacement. Do this in an editor window or in the project (or files) directory tree:

    • Ctrl + H
    • Check "Regular Expression"
    • Search for \n\n
    • Replace with \n
    • Click "Replace all" until all lines are deleted

    If you want to keep a blank line you should:

    • Search for \n\n\n
    • Replace with \n\n

    If you want to replace consecutive lines that are not empty but contain whitespaces only you should:

    • Search for \n[\t\r]+$\n
    • Replace with \n