lethalMango
lethalMango

Reputation: 4491

NetBeans saves code incorrectly (all on one line with squares where the line breaks should be)

Issue 1

I have been using NetBeans on my work machine to develop a PHP website. The issue I have is that using netbeans, in the application itself, every other line is a blank line. Even opening a correctly formatted document will cause this issue. E.g.:

Coded using Notepad:

<p>Test para with
just a standard line break
and just a few more to
show what I mean</p>

When displayed in NetBeans is shows as:

<p>Test para with

just a standard line break

and just a few more to

show what I mean</p>

Issue 2

The main issue I have, is that all files saved are saved in a single line (proven when opened in notepad). This causes me an issue when uploading as it reads the PHP files in a single line so the first comment will cause the rest of the document to be commended:

<?php[]include('lib/config.php');[][]$query = "SELECT * FROM......"[][]// This comment now comments out the rest of the document>

The [] represent the square boxes shown in the notepad file.

I have tried all the formatting settings in NetBeans for PHP but I can't seem to resolve it.

Thanks

Upvotes: 0

Views: 3535

Answers (2)

Tushar Joshi
Tushar Joshi

Reputation: 2224

This question got answered in one way on an old StackOverflow question here.

To change the way how NetBeans IDE editor save your line endings, you can follow the following instruction.

  1. Open the NetBeans Configuration file from NETBEANS_HOME\etc\netbeans.conf where NETBEANS_HOME is the folder where NetBeans IDE is installed, which is usually C:\Program Files\NetBeans IDE 6.9.1 (may change according to your version) in Windows
  2. Update the setting netbeans_default_options and add -J-Dline.separator=CRLF at the end of it.

For example:

netbeans_default_options="...... -J-Dline.separator=CRLF"

--where ....... means existing settings which we have to keep as they are.

References:

  1. Wiki entry at netbeans.org for line endings

with regards
Tushar Joshi, Nagpur

Upvotes: 2

Ernest
Ernest

Reputation: 8829

Notepad uses windows line end style - CR/LF (\r\n), while Netbeans for some reason, opens a file in Linux style (\n). To fix this you can:

  • stop using a Notepad, and use f.i. Notepad++ - where you can configure line ending style. (notepad can't understand LF - so displays it as squares)
  • convert your documents to one chosen style - I always force my software (editors, git, ect) to use LF only. You can do this with NetBeans:
    • Ctrl+Shift+H (opens Replace in projects window)
    • Containing text: \r
    • Replace with: nothing, leave this blank
    • tick Regular Expression
    • find and replace

Backup your data before doing this :)

Upvotes: 0

Related Questions