3.3 Keyboard Shortcuts
Most key presses simply insert a character into the editor, such as a, 3, or (. Other keys and key combinations act as keyboard shortcuts that move the blinking caret, delete a line, copy the selection, etc. Keyboard shortcuts are usually trigger by key combinations using the Control, Meta, or Command key.
Many of the key-binding actions can also be performed with menu items.
C-‹key› means press the Control key, hold it down and then press ‹key› and then release them both. For example: C-e (Control-E) moves the blinking caret to the end of the current line.
M-‹key› is the same as C-‹key›, except with the Meta key. Depending on your keyboard, Meta may be called “Left,” “Right,” or have a diamond symbol, but it’s usually on the bottom row next to the space bar. M-‹key› can also be performed as a two-character sequence: first, strike and release the Escape key, then strike ‹key›. Under Windows and Mac OS X, Meta is only available through the Escape key.
DEL is the Delete key.
SPACE is the Space bar.
On most keyboards, “<” and “>” are shifted characters. So, to get M->, you actually have to type Meta-Shift->. That is, press and hold down both the Meta and Shift keys, and then strike “>”.
Under Windows, some of these keybindings are actually standard menu items. Those keybindings will behave according to the menus, unless the Enable keybindings in menus preference is unchecked.
If you are most familiar with Emacs-style key bindings, you should uncheck the Enable keybindings in menus preference. Many of the keybindings below are inspired by Emacs.}
3.3.1 Moving Around
C-F6 : move the cursor from the definitions window to the interactions window (or the search window, if it is open).
3.3.2 Editing Operations
M-S-L : wrap selection in (lambda () ...) and put the insertion point in the arglist of the lambda
C-c C-o : the sexpression following the insertion point is put in place of its containing sexpression
C-c C-e : the first and last characters (usually parentheses) of the containing expression are removed
C-c C-l : wraps a let around the sexpression following the insertion point and puts a printf in at that point (useful for debugging).
3.3.3 File Operations
The interactions window has all of the same keyboard shortcuts as the definitions window plus a few more:
M-p : bring the previously entered expression down to the prompt
M-n : bring the expression after the current expression in the expression history down to the prompt
3.3.7 LaTeX and TeX inspired keybindings
C-\ M-\ : traces backwards from the insertion point, looking for a backslash followed by a LaTeX macro name or a prefix of such a name. If a macro name is found, it replaces the backslash and the name with the corresponding key in the table below; if a (proper) prefix p is found, it replaces p with the longest common prefix of all macro names that have p as a prefix (unless there is only one such name, in which case it behaves as if p were a complete macro name).These are the currently supported macro names and the keys they map into:
3.3.8 Defining Custom Shortcuts
The Add User-defined Keybindings... menu item in the Keybindings sub-menu of Edit selects a file containing Racket definitions of keybindings. The file must contain a module that uses a special keybindings language, framework/keybinding-lang. To do so, begin your file with this line:
The framework/keybinding-lang languages provides all of the bindings from racket, racket/class, and drracket/tool-lib, except that it adjusts #%module-begin to introduce a keybinding form:
(keybinding string-expr proc-expr)
Declares a keybinding, where string-expr must produce a suitable first argument for map-function in keymap%, and the proc-expr must produce a suitable second argument for add-function in keymap%.
For example, this remaps the key combination “control-a” key to “!”.
#lang s-exp framework/keybinding-lang (keybinding "c:a" (λ (editor evt) (send editor insert "!")))
Note that DrRacket does not reload this file automatically when you make a change, so you’ll need to restart DrRacket to see changes to the file.