eclipse reformat only edited lines - eclipse

I am working with Java. If I hit Ctrl+Shift+F in Eclipse Helios, it will auto format the entire file instead of the lines I edited. This becomes a nightmare at the time of check in when someone else uses a different style on the same file. Is there a way to tell eclipse to only format the touched lines in a file.

Windows-Preferences-Java-Editor-Save Actions
Format only saved lines. However, if you hit Ctrl+shift+f i don't think there is a way that only edited lines will be saved.

If you select a range of lines in the editor then the format is done just on that range, if there is nothing selected the whole file is formatted.
You can change the formatting style used in Preferences / Java / Code Style / Formatter.
You can control formatting and other actions done when saving a file in the Jova / Editor / Save Actions preferences.

Look at the preferences page for the available Save Actions.

Related

VS Code JSON Format Reverts on File Change

I know you can format on demand, save etc. However, I want my JSON files to be formatted automatically when I open them.
I'm currently using Prettier for my default formatter; which works great when I force the formatting through ctrl+shift+p > format document or just pressing ctrl+s does it (because I have that enabled).
I forgot to mention that if I have the file open in the editor (no pending changes) and the file is updated from a source outside of the editor, the formatting resets.
How can I prevent the formatting from resetting after the file is updated?
Does anyone have this working and if so how?

Eclipse - Showing changes before saving

I run into this problem a lot. Sometimes I would edit and forget about it in Eclipse or maybe keyboard moved randomly and input random characters. How do I view current changes compared to the last save easily in Eclipse? That way, I would know what changes took effect before I save.
If you just want to see what lines have changed, then you can follow the instructions in this answer in order to show a highlight of the changed lines on the left-hand side of your editor.
Aside from that I don't think it's easy to tell what's recently been changed without saving. If you do save then you have the option of comparing with the previous version: right-click on the file in the tree and choose "Compare With -> Local History" and then choose a version you saved earlier.
If you save it you can also compare against what's in source control, of course. You are using some sort of source control?
You can use either
compare editor-show changes between 2 or 3 files by showing each file side-by-side
First select the files on the Project Explorer with control-click.
Now right-click -> Select Compare With / Each Other.
or
Quick Diff - General > Editors > Text Editors > Quick Diff

Format only selected code in eclipse

As the title says, I want to format only selected lines of code. I know by pressing Ctrl + Shift +F formats whole file.
Formatting whole file is not good options as it will create lots of conflicts when I will commit the file. I changed a portion of the file (copied some code from internet etc.).
Is there any easy way to format selected lines in eclipse. I have searched a lot but found no solution.
I am working with PHP.
Highlight (left click, drag, left release) the lines you want to format, and press Ctrl + Shift + F, or right click and select Source -> Format.
For Java code, you have to highlight a complete piece of code (statement(s), method).
For PHP, I imagine you would still have to highlight a complete piece of code.
Tested on Windows version of Eclipse 4.2.

Is there a way to copy code from the Eclipse IDE without the rich-text formatting?

Recently every time I copy a block of code from Eclipse and paste the code into TextEdit or a online forum using the code tags, I get the code with the rich-text or html formatting, so I have to copy into a text editor remove the formatting copying and pasting again, In the past this was not a problem I used to copy from eclipse and paste the code without any formatting at all just as plain-text, I dont know if I turn on a property or what I did for this to happen, any ideas how to fix this?
There is an Eclipse bug filed for this that can be voted for:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=45969
It has been open for 10 years though!
There are applications out there that think they can handle rich text but can't. So for those it looks like we'll have to carry on with "Copy-Switch to Notepad-Paste-Select All-Copy-Switch to final app-Paste" for some time yet.
Note: the rich formatting from a SWT editor seems to have always been available (bug 64498).
You could use "Edit, Paste and Match Style" in TextEdit.
From the Edit menu, choose Paste and Match Style,
or use the keyboard shortcut, Shift Option Command V.
The pasted text will pick up all the formatting from the character to the left of the flashing insertion point. This technique works in Mail as well.

Unable to create a file with foreign language characters

I get the following error, when trying to save a properties file (containing name/value pairs) with foreign language characters. How do I set the encoding?
Save could not be completed. Some characters cannot be mapped using
"Cp1252" character encoding. Either change the encoding or remove the
characters which are not supported by the "Cp1252" character encoding.
I presume its eclipse:
Go to Windows Menu –> Preferences –> General (expand it) –> Workspace (click on it)
Look for a box “Text File Encoding”. Default will be “Cp1252″.
Change radio to select other and select “UTF-8″ from combo box.
That looks like Eclipse.
Cut the whole contents of the file into the clipboard.
Save the (now empty) properties file.
Change the encoding settings of the file (Alt+Enter) to be UTF-8 or whatever you need.
Paste the clipboard into the editor.
Save the editor.
Assuming it is in Eclipse, easiest way is to choose Save as UTF-8 option present in the error dialog box.
The other answers work well too.
Best possible solution for this , which I always do .Is to go the respective file in your workspace open it in notepad++ and make the desired changes. Once done , save the file.
Your eclipse will ask you to update the code with the changes . Click yes.
And you are all good to go now.
Fist copy the file and delete that file and then cleat your code in the eclipse after
create file with same content and rewrite the code it will resolve.