Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove empty lines in Netbeans 7.x [closed]

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.

like image 604
Mateng Avatar asked Mar 06 '13 15:03

Mateng


4 Answers

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
like image 91
Code-Source Avatar answered Oct 31 '22 15:10

Code-Source


Try this one...

Ctrl + F (find) in Netbeans as Regular Expression:

\n\s*(\n)

and Replace All by

$1
like image 27
Chintan Hingrajiya Avatar answered Oct 31 '22 14:10

Chintan Hingrajiya


In NetBeans 7.3 (I'm not sure about the earlier version, it should be available in 7.x)

Automatic removal:

Tools > Options > Editor > On Save > Remove Trailing Whitespace:

you can choose from: "None / All Lines / Modified Lines Only"

Manual way:

Alt + Shift + F

like image 9
Tombart Avatar answered Oct 31 '22 13:10

Tombart


Yes there is one and this is a very important feature indeed. It depends on your settings but by default you can press Alt + Shift + F or find it in the context menu: Source > Format.

You can setup your own style for formating here: Tools > Options > Formatting. You can set this for all languages or individualy.

Hope this helps.

like image 3
F. Müller Avatar answered Oct 31 '22 14:10

F. Müller