- Opening the Source Editor
- Managing Automatic Insertion of Closing Characters
- Displaying Line Numbers
- Generating Code Snippets without Leaving the Keyboard
- Using Code Completion
- Inserting Snippets from Code Templates
- Using Editor Hints to Generate Missing Code
- Matching Other Words in a File
- Generating Methods to Implement and Override
- Generating JavaBeans Component Code
- Creating and Using Macros
- Creating and Customizing File Templates
- Handling Imports
- Displaying Javadoc Documentation While Editing
- Formatting Code
- Text Selection Shortcuts
- Navigating within the Current Java File
- Navigating from the Source Editor
- Searching and Replacing
- Deleting Code Safely
- Changing a Method's Signature
- Encapsulating a Field
- Moving a Class to a Different Package
- Moving Class Members to Other Classes
- Creating a Method from Existing Statements
- Creating an Interface from Existing Methods
- Extracting a Superclass to Consolidate Common Methods
- Changing References to Use a Supertype
- Unnesting Classes
- Tracking Notes to Yourself in Your Code
- Comparing Differences Between Two Files
- Splitting the Source Editor
- Maximizing Space for the Source Editor
- Changing Source Editor Keyboard Shortcuts
Formatting Code
When you type or have code generated in the Source Editor, your Java code is automatically formatted in the following ways by default:
- Members of classes are indented four spaces.
- Continued statements are indented eight spaces.
- Any tabs that you enter are converted to spaces.
- When you are in a block comment (starting with /**), an asterisk is automatically added to the new line when you press Enter.
- The opening curly brace is put on the same line as the declaration of the class or method.
- No space is put before an opening parenthesis.
If your file loses correct formatting, you can reformat the whole file by selecting Source | Reformat Code (Ctrl-Shift-F). If you have any lines selected, the reformatting applies only to those lines.
If you have copied code, you can have it inserted with correct formatting by pasting with the Ctrl-Shift-V shortcut.
Indenting Blocks of Code Manually
You can select multiple lines of code and then indent all those lines by pressing Tab or Ctrl-T.
You can reverse indentation of lines by selecting those lines and then pressing Shift-Tab or Ctrl-D.
Changing Formatting Rules
For various file types, you can adjust formatting settings, such as for number of spaces per tab, placement of curly braces, and so on.
To adjust formatting rules for Java files:
- Choose Tools | Options.
- Click Editor in the left panel and select the Indentation tab.
- Adjust the properties for the indentation engine to your taste.
- Reformat each file to the new rules by opening the file and pressing CtrlShift-F (with no text selected).
For other file types, you can change formatting properties in the Advanced Options part of the Options Window and by adjusting that file type's indentation engine.
To change formatting rules for non-Java file types:
- Choose Tools | Options and click Advanced Options.
-
Expand Editing | Indentation Engines, and select the indentation engine for the file type for which you want to modify formatting rules.
If there is no specific indentation engine for your file type, find out which indentation is being used for that file type by expanding Editing | Editor Settings, selecting the editor type, and looking at the value of its Indentation Engine property.
- Adjust the properties for the indentation engine to your taste.
- Reformat each file to the new rules by opening the file and pressing CtrlShift-F (with no text selected).
There are other preset indentation engines available (the "simple" and "line wrapping" indentation engines) you might prefer to use.
To change the indentation engine that is used for a file type:
- Choose Tools | Options and click Advanced Options.
- Expand Editing | Editor Settings and select the node for the editor type for which you want to change the indentation engine.
- Select the indentation engine from the Indentation Engine property's combo box.
- Reformat each file to the new rules by opening the file and pressing CtrlShift-F (with no text selected).
To create a new indentation engine:
- Choose Tools | Options and click Advanced Options.
- Expand Editing | Indentation Engines, right-click the node for the indentation engine on which you want to base your new indentation engine, and choose Copy.
- Right-click the Indentation Engines node and choose Paste | Copy.
- Modify the name of the indentation inline and adjust the properties to your taste.
- In the Advanced Options part of the Options dialog box, expand Editing | Editor Settings and select the node for the editor (such as Java Editor or HTML Editor) that you want the indentation engine to apply to.
Changing Fonts and Colors
You can adjust the fonts that are used in the Source Editor and the way colors and background highlighting are used to represent syntactic elements of your code. You can make changes that apply to all file types and changes that apply to specific file types.
To make changes in fonts and colors that are reflected throughout all editor types:
- Choose Tools | Options and click the Fonts & Colors panel.
- In the Languages drop-down list, select All Languages.
- In the Category list, select Default.
-
Use the Font, Foreground, Background, Effects, and Effect Color fields to change the appearance of that code element.
These changes should be reflected in the syntax categories for all the languages, since other categories are essentially designed as customizations of this one.
To change fonts and colors for a specific code syntax element:
- Choose Tools | Options and click the Fonts & Colors panel.
-
Select the editor type from the Languages drop-down list.
If the syntax element applies to multiple languages, select All Languages.
- Select a syntax element in the Category list.
- Use the Font, Foreground, Background, Effects, and Effect Color fields to change the appearance of that code element.