How to Change the Default Format Settings in Eclipse

Download ArticleDownload Article

Do you get tired constantly having to re-format your programming code? With a single press of Control+Shift+F, Eclipse will format your entire document for you. Follow the steps below to change the way Eclipse will format your document to your own personal preferences.

  1. How.com.vn English: Step 1 Open the Eclipse program.
    Click the Window option in the top tool bar and then click Preferences.
  2. How.com.vn English: Step 2 Using the left side of the box, expand the Java option, then expand Code Style and finally click Formatter.
    Advertisement
  3. How.com.vn English: Step 3 Notice the active...
    Notice the active profile should be set to “Eclipse [built-in]” you cannot edit this setting, so make a new one by clicking the “New...” button underneath.
  4. How.com.vn English: Step 4 Enter the “profile name”.
    Pick a name that is significant to you so that you will remember what it is. The “Initialize setting with the following profile” option should have “Eclipse [built-in]” selected. The “Open the edit dialog now” should also be selected. Now click “OK” to create your new format settings.
  5. How.com.vn English: Step 5 Observe are now presented with the “Profile ‘name you selected’” box.
    There will be 8 tabs, named as follows:
    • Indentation
    • Braces
    • White space
    • Blank lines
    • New lines
    • Control statements
    • Line wrapping
    • Comments
      There will be an “Apply” and “OK” button at the bottom. You should make sure that you hit the “Apply” button every time you make a change so that it will know it is definitely saved and applied to your format settings.
  6. How.com.vn English: Step 6 Refer to the picture at the right to see the INDENTATION TAB.
    Indentation is very important because it makes a program more readable if done properly. In the General Settings area, you can change the size of the tab, which you can set depending on whether you want to save space or if you want to differentiate the different sections more easily. According to coding conventions, you should leave all the boxes in the Indent section checked (Empty lines box does not matter). Do not forget to click Apply.
  7. How.com.vn English: Step 7 Click on the BRACES TAB, and refer to the picture to the right if necessary.
    The braces settings are fairly simple and are based on personal preference. Most people either use the “Same line” or “Next line” position. You should use the same position for every option. Do not forget to click Apply.
  8. How.com.vn English: Step 8 Click the WHITE SPACE TAB.
    Use the picture to the right for reference. Once again, this tab is for personal preference and ease of reading. There are many options to expand, read through and then select or deselect according to your preference on where you want a space (means one click of the space bar) to be added or removed. Do not forget to look in the preview window to see the change and click Apply often, seeing as there are many options in this tab.
  9. How.com.vn English: Step 9 Click the BLANK LINES TAB and use the picture as a reference.
    This tab allows you to specify the number of blanks lines before or after different declarations. The standard is usually either 0 or 1 depending on the option. If you use more than 1 blank line, it is just wasting space. Choose the options according to you preference. Do not forget to select Apply.
  10. How.com.vn English: Step 10 Look at the picture to the right and then click on the NEW LINES TAB.
    This tab is purely for user preference, so choose options as you desire. Do not forget to click Apply.
  11. How.com.vn English: Step 11 Observe the CONTROL STATEMENTS TAB is for your personal preference.
    Refer to the picture to the right, while selecting the boxes. The document is easily read with or without the added space after a control statement. To limit the length of your document leave the boxes unchecked. Do not forget to click Apply.
  12. How.com.vn English: Step 12 Click the LINE WRAPPING TAB and see the picture to the right.
    In the “Line width and indentation levels” section choose how many characters wide your document can be and how wide you want the indent to be for the wrapping of the line(s). Below, click each option and choose the “Line wrapping policy” and “Indentation policy” accordingly. You want your document to have the littlest amount of wrapping as possible, so that it is easy to read. Do not forget to select Apply often, since there are a lot of options.
  13. How.com.vn English: Step 13 Set the options in the COMMENTS TAB.
    This is the last tab to set and the picture to the right is for reference. The options that begin with “Enable...” should be selected. The other options can be selected for personal preference. Selecting all the options that will “Remove blank lines.” is reccomended. Do not forget to click Apply.
  14. How.com.vn English: Step 14 Check out the sample program.
    As an example, to show you how the format will work, there is a sample program (click on the picture at the right) shown with the formatting distorted (i.e. wrong indentation, extra spaces, etc.).
  15. How.com.vn English: Step 15 Format the currently selected document.
    Click on Source in the top tool bar and then click Format or as a shortcut you can click “Control + Shift + F”.
  16. How.com.vn English: Step 16 Click on the picture to the right.
    Here you can see that the indentation has been restored, excess space has been removed and brackets are placed as per the users preference. Your document will not, necessarily look like the example as you've used your own personal coding style preference.
  17. Advertisement


Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Tips

      • When you click or unclick a setting the preview screen to the right will show you the change it will make to the format setting.
      • You should not go any smaller than a tab size of 2.
      • Do not be afraid to make changes as you can always restore the default settings.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      • If you do not select Apply before closing the profile box all changes will be lost.
      Advertisement

      Things You'll Need

      • Computer
      • Source code written by you
      • Eclipse (Version used for this article: Eclipse SDK 3.4.1)

      References

      1. Eclipse SDK. [Software Download]. Portland, OR: The Eclipse Foundation, 2008. Available: http://www.eclipse.org.

      About This Article

      Tested by:
      How.com.vn Technology Team
      How.com.vn is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 12 people, some anonymous, worked to edit and improve it over time. This article has been viewed 247,775 times.
      How helpful is this?
      Co-authors: 12
      Updated: February 5, 2022
      Views: 247,775
      Categories: Software
      Thanks to all authors for creating a page that has been read 247,775 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement