Source Editor Tips

The following table shows how to accomplish some common tasks and gives you some tips for working in the IDE's Source Editor.

To perform this task Follow these steps
Handle the automatic insertion of quotation marks, parentheses, and so on.

When you type a character that typically is used in pairs (such as a quotation mark or a parenthesis, the IDE also automatically inserts the closing character (such as another quotation mark or the closing parenthesis). If you find this distracts your typing, you can simply type the closing characters as you would normally. The IDE will use the closing character that you type and delete the character that it inserted.

Format code automatically with consistent indentation.
  • Right-click in the Source Editor and choose Reformat Code.

    If any text is selected, only that text will be reformatted. If no text is selected, then the whole file is reformatted.

Find the appropriate code element (class, method, or field) and insert it into your code.
  1. When typing in the Source Editor, press Ctrl-Space to open the code completion box.
  2. Scroll the list of code elements provided, select the one you want, and press Enter.
Insert a commonly used code snippet.
  • Type the abbreviation for the code snippet and press Shift-Space.

See Code Template Abbreviations: Quick Reference.

Quickly insert a word that you have already typed elsewhere.
  1. Type the beginning character of the word that you have previously typed.
  2. Type Ctrl-K to insert the closest previous word that matches those beginning characters.

For example, consider the following code:

BufferedReader br = new BufferedReader(...)

You can save yourself several keystrokes by doing the following:

  1. Type
    BufferedReader br = new B
  2. Press Ctrl-K to insert ufferedReader

See Using the Word Match Feature for more information.

Go to the Java source for the identifier the insertion point is on.
  • Press Alt-O, or choose Navigate > Go to Source.
Go to a Java file via hyperlinks.
  • Hold down the Ctrl key and, at the same time, move your mouse over and click a Java identifier (package, class, method, variable).
Go to a Java class.
  • Choose Edit  > Go To Class or press Alt-Shift-O. .

Jump to the declaration for the Java method or field the insertion point is on.
  • Press Alt-G, or right-click and choose Go To > Declaration from the pop-up menu.
Go to a specific method or field in the currently displayed Java class.
  • Double-click the method or field in the Navigator window.
Jump back and forth among areas of code in which you have been working.
  • Use the Alt-K and Alt-L jump list keyboard shortcuts.
Bookmark a line of code.
  • Click anywhere in the line that you want to bookmark and press Ctrl-F2.

    Press F2 to cycle through your bookmarks.

    Press Ctrl-F2 on a bookmarked line to remove the bookmark.

Maximize the Source Editor.

Do one of the following:

  • Double-click a file's tab in the Source Editor.
  • Make sure that the Source Editor window has focus and then press Shift-Escape.
  • Choose Window  > Maximize.
Revert a maximized Source Editor to its previous size.

Do one of the following:

  • Double-click a file's tab in the Source Editor.
  • Press Shift-Escape.
  • Choose Window  > Restore.
Display line numbers. Choose View > Show Line Numbers.
View two files simultaneously.
  1. Open two or more files.
  2. Click the tab of one of the files and drag it to the side of the window where you want the file to be placed. When a red preview box appears to show you where the window will be placed, release the mouse button to drop the window.

    The window can be split horizontally or vertically, depending on where you drag the tab.

Split the view of a single file.
  1. Right-click the document's tab in the Source Editor and choose Clone Document.
  2. Click the tab of the cloned document and drag it to the part of the window where you want the copy to be placed.

Legal Notices