48

Need to keep EOL format consistent in all resources under Eclipse workspace.

I know about Eclipse preference that sets new line style for newly created files, but I would like to have automatic conversion for already existing files. Is there some settings/plugins?

I want just setup once and be sure that all line endings are in the same format.

4 Answers 4

83
+50

In addition to the Window > Preferences > General > Workspace setting for new files that you already know about, there is a File > Convert Line Delimiters To option. I don't know of any existing plugin/tool that will do this automatically when you save, but you could certainly write one or make converting the line ending part of your process.

To make it easier on yourself, you can bind keyboard shortcuts to the conversion commands by going to Window > Preferences > General > Keys and filtering using "delimiter": binding a shortcut to EOL conversion

3
  • Thank you, but I know about that command. I have to use it regularly. Problem is that I can notice wrong line endings only after commit. And that's difficult to fix then. Aug 9, 2011 at 7:18
  • 1
    You might be able to use the solutions listed here to automate this: stackoverflow.com/questions/1012230/… Aug 9, 2011 at 14:33
  • 6
    @IlyaIvanov - try enabling 'General > Editors > Text Editors > Show whitespace characters' setting and set visibility to '70' or so; as a plus you will now be able to see tabs/spaces formatting at a glance. Jan 26, 2015 at 15:18
39

In Eclipse, to convert the line endings for existing files:

  1. Go to the file browser view, and click on the project/folder/file that you wish to convert.

  2. From the menu bar, select File > Convert Line Delimiters To > Windows / Unix / MacOS 9.

Eclipse: Convert Line Delimiters To

1
  • 7
    this converts through your file structure starting at the resource selected on your Package Explorer, If you select a file, just that file will be converted, but if you select a folder a new windows will pop-up for you to refine your selection.
    – Legna
    Sep 23, 2015 at 16:04
2

You can Search your resources with the Search-Dialog and go to the tab File Search. There you can enter a Regular expression. Enter \r\n or whatever line ending you want to change.

Then hit the Replace .. Button instead of Search.

I want just setup once and be sure that all line endings are in the same format.

... ok, my answer does not consider this.

1

You might get usefull results with Eclipse save actions: If the eclipse formatter also converts the EOL style, you could use it to modify EOL style only for the files you are modifying.

Unfortunately I don't have eclipse here, so I can't test if this actually works. Worth a try, however.

1
  • This is an interesting point, however I don't like to use eclipse formatter on the whole file. It produces non nice code sometimes... Aug 12, 2011 at 8:48

Your Answer

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

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