19

The version of NetBeans that I use is 6.5.1

9 Answers 9

27

Quoted from the Netbeans Wiki:

NetBeans editor respects the line separator used in an existing file. It reads the file into an editor document instance in the following way:

  • First line of the file is read and the line separator type is determined - it is expected to be one of

  • "\n" (LF)- Unix

  • "\r" (CR)- Mac

  • "\r\n" (CRLF) - Windows

  • The line separator type is remembered in the document instance for future save operation.

  • All the lines in the file are read and their line separator (regardless of what type it is) is translated to "\n" that is the only line separator type that the editor is able to work with.

  • Upon save operation each "\n" in the document is translated into the remembered line separtor type.

Note: If there would be a mixture of line separators of multiple types throughout the file then only the line separator type from the original first line will be used upon save.

For new files (constructed from templates) the editor uses platform-default line separator.

Update:

As of Netbeans 7.3 there is a new change-line-endings-on-save plugin that allows you to configure line endings globally or per-project.

4
  • 3
    Does this mean there's no way to manually change this behaviuor?
    – Exander
    Jun 18, 2009 at 10:59
  • 3
    I don't believe so. The wiki states: "Currently there are no additional options for handling line separators." Jun 18, 2009 at 13:53
  • @AllySutherland, is their any free tool to covert one type to another type. I'm using windows. Jul 31, 2013 at 4:54
  • I used this line-endings-on-save on windows7 with Unix line ending and it does not work. At least themecheck Wordpress plugin is still showing mixed line ending. Oct 14, 2013 at 18:43
16

There is a plugin that will help to switch the line endings. It is 'Show and change line endings'. You can install it directly within NetBeans.

Go to Tools->Plugins->Available Plugins
Then search for it. Check the checkbox and press 'Install' button.

3
  • err...sorry, I switched to emacs some time ago, and right now it's of no consequence to me which style of newlines is used in the files.
    – Exander
    Jul 25, 2012 at 10:49
  • 3
    It may be helpful to others searching for as this page appears in first page of google search :) And NetBeans not yet have this feature by default.
    – Junaid
    Jul 25, 2012 at 16:06
  • Good for Netbeans 12.6 Mar 25, 2022 at 1:42
1

There is a platform specific property that you may use make your code cross platform. See http://java.sun.com/docs/books/tutorial/deployment/applet/properties.html

String newline = System.getProperty("line.separator");

1
  • I believe he's talking about the actual Java source files.
    – Michael Myers
    Jun 12, 2009 at 12:53
1

I don't know how to do this using NetBeans, but if you store your code in a Subversion repository, you might want to look into the svn property svn:eol-style.

1
  • if you store your code in a Subversion repository you have bigger problems that EOL :) Mar 25, 2022 at 1:31
1

Please use this netbeans plugin

http://plugins.netbeans.org/plugin/36810/show-and-change-line-endings

1

recently updated to 7.2 and started to search for the solution I had at 7.1.2 version. Take a look at this plugin that helps to switch between line endings types.

1

Install https://plugins.netbeans.apache.org/catalogue/?id=31 in netbean and it will show the line break in bottom right task bar inside netbean also you can switch between Windows, Linux and Mac.

0

I think you can't. NB will use the native OS format where it is running. If you have issues with that, there is an Ant FixCRLF task.

-2

What is your goal - to have a work flow using only Unix line-endings?

As has already been pointed out - there isn't any functionality in Netbeans to convert from one line ending to the other.

New PHP files created in NetBeans (File > New File > PHP) have Unix line endings by default.

This doesn't really give you the functionality you asked about but Netbeans will respect the file endings of existing files and create new PHP files with Unix line endings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.