The function of the keyboard can be extensively customized in Eclipse. Within Eclipse, key strokes and key sequences are assigned to invoke particular commands.
A 'key stroke' is the pressing of a key on the keyboard, while optionally holding down one
or more of these modifier keys: Ctrl
, Alt
(Option
on the Macintosh), Shift
, or
Command
(only on the Macintosh.) For example, holding down Ctrl
then
pressing A
produces the key stroke Ctrl+A
. The pressing of the modifier keys themselves
do not constitute key strokes.
A 'key sequence' is one or more key strokes. Traditionally, emacs assigned two or three key stroke key sequences to particular
commands. For example, the normal key sequence assigned to Close All
in emacs is Ctrl+X Ctrl+C
.
To enter this key sequence, one presses the key stroke Ctrl+X
followed by the key stroke Ctrl+C
.
Eclipse supports key sequences of arbitrary lengths.
A 'key binding' is the assignment of a key sequence to a command.
A 'configuration' is a set of key bindings. Eclipse includes two configurations:
The Standard configuration contains a general set of key bindings, in many cases recognizable to
users as traditional key sequences. For instance, Ctrl+A
is assigned to Select All
,
Ctrl+S
is assigned to Save
, etc.
Ctrl+X H
is assigned to Select All
, Ctrl+X S
is assigned to Save
, etc.
It is important to understand why the Emacs configuration says that it 'extends Standard'. The Emacs configuration
is not a complete set of key bindings like the Standard configuration. Rather, it borrows from the Standard
configuration where possible, only defining explicit emacs style key bindings where they vary from the
Standard configuration. Generally, only well known commands like Select All
, Save
, etc. have specific emacs key sequences associated with them.
The user decides which configuration they are most comfortable using by changing the 'Active Configuration' setting on the keys preference page. If the user chooses the Standard configuration, all Emacs key bindings are ignored. If the user chooses the Emacs configuration, explicit emacs style key sequence assignments take precedence over any conflicting assignments in the Standard configuration.
Key bindings can vary based on the current context of Eclipse.
Sometimes the active part might be a java file editor, for instance, where a different set of
key sequence assignments may be more appropriate than if the active part was an html file editor.
As a specific example, typically Ctrl+B
is assigned to Build
in a context such as java file editing,
while Ctrl+B
is assigned to Make Text Bold
in a context such as html file editing. This context is called
'scope' and is determined by the active part. If the active part does not choose a particular scope, the workbench
will set the active scope to Global.
Eclipse includes three different scopes. They are:
Much like configurations, scopes can extend other scopes. For example, the Java Editor scope borrows key bindings from the Text Editor scope, which in turn borrows key bindings from the Global scope.
Key bindings also vary by platform and locale. On the Macintosh platform, Command+S
is assigned to Save
, instead of the usual Ctrl+S
. On Chinese locales (zh), Alt+/
is assigned to Content Assist
, instead of the usual Ctrl+Space
.
The current platform and locale is determined when Eclipse starts, and does not vary over the course of an Eclipse instance.
With multi-stroke key sequences, configurations, and scopes, there are a lot of things to keep in mind when customizing key bindings. To make things easier, all key customization is done on the Keys preference page.
Select Window > Preferences > Workbench > Keys for the Keys preference page.
Close
from the list of commands. Information on this command, along with its current key bindings, is shown on the right side.
Notice that Close
has two key sequences assigned to it: Ctrl+F4
in the Standard configuration and Ctrl+X K
in the Emacs configuration. Both are assigned in the Global scope. Thus, if the user sets the active configuration to Standard, Ctrl+F4
will be assigned to Close
while Ctrl+X K
will not. If the user sets the active configuration to Emacs, however, Ctrl+X K
will be assigned to Close
. As well, because the Emacs configuration also borrows key bindings from the Standard configuration, Ctrl+F4
will also be assigned to Close
provided that Ctrl+F4
has not been assigned to another command in the Emacs configuration.
Below the list of key sequences assigned to Close
, there is a place to add or remove key bindings. By default, it selects the scope as Global and the configuration to be the user's active configuration (recall above where we changed this to Emacs).
We type in the key sequence Ctrl+W
, and the 'Add' button becomes enabled. Also, a list of all the commands to which the key sequence
Ctrl+W
is already assigned is show below the Add button. We can see that Ctrl+W
is currently assigned to the command Cut
in the Global scope and Emacs configuration. We click the 'Add' button to assign Ctrl+W
to Close
.
Ctrl+W
added to the list of key sequences assigned to
Close
. Notice the small 'change' graphic Ctrl+W
to
Cut
. We can remove this change at any time by selecting our new key
binding and clicking the 'Remove' button. The previous assignment of Ctrl+W
to Cut
will automatically be restored.
Cut
, we can see the results of our change. Notice the small 'minus' graphic
Cut
in the Emacs
configuration, say Ctrl+Alt+W
. Adding this in the previous manner
above produces the following. Notice the small 'plus' graphic
Key bindings are provided by plug-ins, and in Eclipse, plug-ins can be added or removed. This can cause key bindings declared by these plug-ins to be added or removed. Eclipse stores custom key bindings in a way to automatically compensate for this. Consider the example above where Ctrl+Alt+W
was assigned to Cut
in the Emacs configuration. Consider the user installs a new plug-in which assigns Ctrl+Alt+W
to a particular command. Eclipse will preserve the user's assignment to Cut
, but show the key binding with the small 'change' graphic instead of the 'plus' graphic.
There are only a finite number of simple, common key strokes available to assign to a multitude of commands. We have seen that configuration, scope, platform, and locale all partition key sequence assignments into domains where they don't conflict with one another. Consider the case for Ctrl+B
above if scopes did not exist. One plug-in would assign Ctrl+B
to Build
, the other plug-in would assign Ctrl+B
to Make Bold Text
. How would Eclipse properly resolve this conflict?
Though conflicts are drastically reduced by employing the above mechanisms, they can still occur. Two plug-ins, independent of one another, could assign the same key sequence to different commands with the same scope, configuration, platform, and locale. Consider if a plug-in assigned Ctrl+F4
in the Global scope and Standard configuration to one of its commands. This directly conflicts with Eclipse assigning Ctrl+F4
to the close command in the same scope and configuration.
Ctrl+F4
effectively useless in this scope and configuration.
Conflicts of this nature are shown in the Keys preference page as follows. Notice the red text and the word "[conflict]":
These types of conflicts can be resolved by the user explicitly assigning the key sequence to one of the commands.
Another type of conflict can be caused by multiple-key stroke key sequences. For example, in the Emacs configuration, there are many multiple-key stroke key sequences beginning with the key stroke Ctrl+X
. Ctrl+H K
is assigned to Close
. Ctrl+X H
is assigned to Select All
.
As previously mentioned, the Emacs configuration borrows key bindings from the Standard configuration. In the standard configuration, Ctrl+X
is assigned to Cut
. Though the Emacs configuration doesn't explicitly redefine Ctrl+X
, pressing Ctrl+X
is required as part of many of its key bindings. In the Emacs configuration, when one presses Ctrl+X
, one is half way to entering one of many possible assigned key sequences. One would not expect the Cut
action to be invoked at this time.
For this type of conflict, the rule is that the Ctrl+X
key sequence assigned to Cut
would be ignored. Otherwise, it would not be possible to complete many of the key bindings in the Emacs configuration.
Accessibility Features in Eclipse
Changing the key bindings
Online help system