Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 700
Arif Avatar asked Apr 17 '13 07:04

Arif


People also ask

How do I format a selection in eclipse?

To format only selected lines within the script: Select the relevant lines. Go to Source | Format Active Elements -or- press Ctrl+I.

How do I format a block of code in Eclipse?

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).

Does Eclipse have auto format?

Importing preferences for automatic formatting. Eclipse has the capability to do so some automatic formatting whenever a file that is being edited is saved.


1 Answers

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.

like image 183
Gilbert Le Blanc Avatar answered Sep 22 '22 22:09

Gilbert Le Blanc