Emacs Keybindings - Firefox

From MozillaZine Knowledge Base
Revision as of 09:21, 28 October 2004 by Jesse (talk | contribs)
Jump to navigationJump to search

Firefox uses the GTK setting to determine whether Emacs-like/Readline-like keybindings are active in text fields, regardless of what window manager you use. To enable these keybindings, add the line

gtk-key-theme-name = "Emacs"

to ~/.gtkrc-2.0 (create the file if it doesn't exist).

If you use Gnome, you can set this using Desktop Preferences > Keyboard Shortcuts instead of editing the configuration file.

The shortcuts are often called Emacs keybindings, but they're actually more similar to keybindings in Readline. When these keybindings are enabled, they override the standard keybindings in Gnome and Firefox (when a text entry field has focus).

Ctrl+A Go to beginning of line
Ctrl+E Go to end of line
Ctrl+F Go right one character
Ctrl+B Go left one character
Ctrl+K Delete to end of line
Ctrl+U Delete entire line (different from readline, in which Ctrl+U deletes to the beginning of the line)
Ctrl+W Delete word, left
Ctrl+H Delete character, left (backspace)
Ctrl+D Delete character, right

Additional Readline keys not supported by Firefox:

Ctrl+T transpose characters
Ctrl+Y yank (like paste)
Ctrl+P previous line (like Readline's Up)
Ctrl+N next line (like Readline's Down)
Ctrl+S search
Ctrl+R reverse search
Ctrl+J return
Ctrl+M carriage return
Ctrl+L redraw

If you don't use an operating system that has GTK (popular examples include Microsoft Windows and Mac OS X (which happens to use these bindings in nearly every program)), then you must unfortunately manually edit the res/builtin/platformHTMLBindings.xml file and add the following lines:

    <!-- Emacsish single-line motion and delete keys -->
    <handler event="keypress" key="a" modifiers="control"
        command="cmd_beginLine"/>
    <handler event="keypress" key="e" modifiers="control"
        command="cmd_endLine"/>
    <handler event="keypress" key="b" modifiers="control"
        command="cmd_charPrevious"/>
    <handler event="keypress" key="f" modifiers="control"
        command="cmd_charNext"/>
    <handler event="keypress" key="h" modifiers="control"
        command="cmd_deleteCharBackward"/>
    <handler event="keypress" key="d" modifiers="control"
        command="cmd_deleteCharForward"/>
    <handler event="keypress" key="w" modifiers="control"
        command="cmd_deleteWordBackward"/>
    <handler event="keypress" key="u" modifiers="control"
        command="cmd_deleteToBeginningOfLine"/>
    <handler event="keypress" key="k" modifiers="control"
        command="cmd_deleteToEndOfLine"/>


    <!-- Emacsish single-line motion and delete keys -->
    <handler event="keypress" key="a" modifiers="control"
        command="cmd_beginLine"/>
    <handler event="keypress" key="e" modifiers="control"
        command="cmd_endLine"/>
    <handler event="keypress" id="key_left" key="b" modifiers="control"
        command="cmd_charPrevious"/>
    <handler event="keypress" id="key_right" key="f" modifiers="control"
        command="cmd_charNext"/>
    <handler event="keypress" id="key_delback" key="h" modifiers="control"
        command="cmd_deleteCharBackward"/>
    <handler event="keypress" id="key_delforw" key="d" modifiers="control"
        command="cmd_deleteCharForward"/>
    <handler event="keypress" id="key_delwback" key="w" modifiers="control"
        command="cmd_deleteWordBackward"/>
    <handler event="keypress" id="key_del_bol" key="u" modifiers="control"
        command="cmd_deleteToBeginningOfLine"/>
    <handler event="keypress" id="key_del_eol" key="k" modifiers="control"
        command="cmd_deleteToEndOfLine"/>

    <!-- Emacsish multi-line motion and delete keys -->
    <handler event="keypress" id="key_linedown" key="n" modifiers="control"
        command="cmd_lineNext"/>
    <handler event="keypress" id="key_lineup" key="p" modifiers="control"
        command="cmd_linePrevious"/>