Editor
NetBeans - Editor Module Home Page
Links: Home | New Features | User's View | Tips and FAQ
NetBeans Editor is a full-featured
source editor that is integrated with the Form Editor, Explorer, Compiler,
and Debugger. It is the default viewer for all Java, HTML, and plain text
files as well as any other types of files specified by installed
extension modules.
Content
Here you can find all important information about editor module:
Do you want to know what we have planned for the near future or
which features were recently implemented? Click the link to get the overview of
features planned for recent versions of NetBeans.
This section contains details about Editor from user's point of view.
You will find out more about Editor features, shortcuts, available abbreviations,
customization, and other aspects of using the NetBeans Editor.
If you have a problem or question, try the Tips and FAQ page.
If the necessary information is not present there feel free to ask
on Mailing lists.
Cool Features
Now we would like to briefly highlight some of the advanced features of
the Editor. Most of them are specific to the Java Editor.
-
Code Completion
Code completion allows you to type a few characters and then display
a list of context-sensitive possibilities to complete the text you are
typing. For example, in the Java Editor code completion brings up a list
of possible classes, methods, variables, packages, and so on that can be
used to complete the expression.
In the case of HTML files, it can suggest names of tags, their attributes,
possible values, names of matching end tags, and names of entity references.
Code completion can be triggered by pressing [CTRL+SPACE]
or by typing a hotchar or keyword, such as '.' or 'new ' in Java, or '<' in HTML.
For more information about how to use and configure this feature,
see our User's View page on Code Completion.
Code Templates allow you to predefine a set of parametrized mappings between
an abbreviation and full text, e.g. "fori" is shorthand for
for (int i = 0; i < arr.length; i++) {
|
}
Typing the abbreviation followed by [
SPACE] expands
the code template. If there were parameters defined
(e.g. "
i" in the example above) the first parameter will be selected
and its value can be modified (value will be propagated to all
parameter's occurrences automatically). [
TAB] selects
next parameter. [
ENTER] stops editing and jumps
to target caret position that can be defined in the code template.
You can configure code templates
at Tools->Options->Editor->Code Templates.
Word matching is a dynamic approach to entering frequently used words.
After you type the first part (the prefix) of a desired word, the Editor
can generate the rest of the word based on a list of all words
in the document with the same prefix. You can search through the
matching words in reverse [CTRL+K] or forward [CTRL+L]
direction. If your first match does not generate the desired word, you
can press Ctrl-K or Ctrl-L multiple times to find additional matches.
-
Fast Open
Fast Open speeds up the opening of files. Press [ALT+SHIFT+O]
to display the Fast Open dialog box, in which you start typing a class name.
As you type, all available files are shown that match the typed prefix.
The list of files is generated from all source codes opened in current
project. Choose a file to open from the list at
any time. This way you can quickly get to the file you are looking for, with
a minimum of typing or navigating through filesystems.
Fast Import is a bit similar to the Import Management Tool. When you
are using a class and you are not sure whether it is imported, position the
caret in the class name and press [ALT+SHIFT+I]. A
dialog box with possible import statements is displayed so you
can choose one and automatically insert it into your source code.
Hyperlink navigation enables you to navigate easily through your source codes.
To activate a hyperlink hover over a field or class and press the CTRL key.
The element will turn blue and will become underlined. By left-clicking you will
move to the declaration of that element. Thanks to this you can easily access all
your source codes or libraries (if they are distributed with sources).
The Editor is able to reformat your source code. Reformatting rules are defined
by the Indentation Engine property found at
Tools->Options->Editor Settings-><specific_editor>.
Currently, the most interesting indentation engine is the Java Indentation
Engine. According to your configuration, a whole file or only the
selected block of lines can be quickly reformatted by pressing
[CTRL+SHIFT+F].
-
Macro Recording
You can record a sequence of actions performed in the Editor and assign
them a shortcut. Type [CTRL+J S] (type Ctrl-j, then type s) to start
recording, enter any sequence of keystrokes in the Editor, and then
type [CTRL+J E] to stop macro recording. A dialog box is displayed
where you can edit the just-recorded macro and assign it a keyboard shortcut.
Replay the macro using the shortcut you specified.
All existing macro definitions can be found in the Macros property at
Tools->Options->Editor Settings-><specific_editor>.
You can reconfigure the keyboard shortcuts for your macros using the Key
Bindings property.
To get an idea how capable macros are, check out the "debug-var" macro.
By default, it is invoked with [CTRL+J D]. The macro takes the word
at the caret and generates the debugging statement:
System.err.println("your-word-at-caret = " + your-word-at-caret);
The Jump List History automatically stores a list of locations of
modifications made in the Editor, and allows you to jump back to these locations.
It is also possible to jump to another document if the previous modification
occured there, because the history is maintained for all open documents.
Use [ALT+K] to jump to the previous entry in the history, and
[ALT+L] to jump to the next entry.
The jump list shortcuts come in handy in two situations:
-
when you want to go back and forth to places where you made
previous modifications
-
after you use actions that move the caret to another location, such as
Find, Go to Source, or Go to Declaration
You can also use [ALT+SHIFT+K] and [ALT+SHIFT+L] to jump
to the previous or next entries in the jump list history that are not in
the current file.
Often when you are editing a document it is handy to quickly
put bookmarks in different parts of the document and then traverse between
these bookmarks. The bookmarks are displayed in the document as lines with
a colored background.
Use [CTRL+F2] to add and remove bookmarks, and [F2]
to traverse between them.
-
Javadoc in Code Completion
By default, a small Javadoc box appears near the code completion box when
you are using Java code completion. Any available documentation is displayed
for the class, field or method that is selected in the code completion box. For more information
about how to use and configure this feature, see our User's View page on
Code Completion
Javadoc.
In addition to the features above, there are lot of other features that
can be triggered by keystrokes. Here are several that are useful
to speed up your coding when editing Java source code:
[ALT+O] Go to source.
This shortcut opens the file where the item at the caret is defined.
[ALT+G] Go to declaration. Similar to the previous shortcut, this
opens the file where the variable at the caret is declared.
[ALT+F1] Show Javadoc. If your Javadoc documentation is mounted
this shortcut opens the Javadoc for the item at the caret.
[CTRL+[] Find matching bracket. Position the caret after a bracket,
then use this shortcut to move to the matching bracket.
[CTRL+SHIFT+[] Find matching bracket and select block. This is the
same as the above, but the block in brackets is selected.
[CTRL+SHIFT+T] Comment out the current line or all selected lines
with line comment ("//").
[CTRL+SHIFT+D] Remove comments. All line comments ("//") are removed
from the beginning of the current line or selected lines.
All other shortcuts can be found in
Appendix A - Default Keyboard
Shortcuts. In the IDE you can configure global keyboard shortcuts (that
apply to all types of editors) using the Global Key Bindings property at
Tools->Options->Keymap.