On this page:
3.3.4Search
3.3.5Evaluation
top
up

3.3Keyboard ShortcutsπŸ”— i

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.

The keyboard shortcuts are displayed using the same string-encoded notation for modifier keys as map-function in keymap% and the Keybindings view;

  • s: — All platforms: Shift

  • c: — All platforms: Control

  • a: — Mac OS: Option

  • m: — Windows: Alt; Unix: Meta; Mac OS: Command, when map-command-as-meta-key produces #t

  • d: — Mac OS: Command

  • l: — All platforms: Caps Lock

  • g: — Windows: Control plus Alt as AltGr; see get-control+meta-is-altgr in key-event%

  • ?: — All platforms: allow match to character produced by opposite use of Shift, AltGr/Option, and/or Caps Lock, when available; see get-other-shift-key-code in key-event%

If a modifier key is not specified, it matches whether that modifier is pressed or not pressed. A ~ prior to a modifier indicates the keybinding only activates if that modifier is not pressed.

A keyboard shortcut that begins with : only activates if the modifiers Shift, Control, Option, Alt, Meta, or Command are not pressed.

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. On Mac OS, Meta is, by default, available only through the Escape key. But the preferences dialog (in the General Editing sub-panel of the Editing panel) has check boxes that adjust the handling of the Alt key or the Command key to be meta.

delete 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 “>”.

On Windows (and sometimes under Unix) 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. For example, the c:e keybinding mentioned above actually toggles the visibility of the interactions window.

If you are most familiar with Emacs-style key bindings (especially on windows or some linux installations where the control key is, by default, for the menu shortcuts), you should uncheck the Enable keybindings in menus preference. Many of the keybindings below are inspired by Emacs. See also Defining Custom Shortcuts for suggestions on how to bind keys to menu items on a selective basis.

Some keybindings are not available if Enable keybindings in menus is enabled.

And finally, the authoritative source for keybindings is the Edit menu’s Show Active Keybindings menu item. Keybindings in DrRacket are often sensitive to the window that has the keyboard focus, so the contents of the window that Show Active Keybindings opens will depend where the keyboard focus was when the menu was selected.

3.3.1Moving AroundπŸ”— i

  • c:f : move forward one character

  • c:b : move backward one character

  • m:f : move forward one word

  • m:b : move backward one word

  • c:v : move forward one page

  • m:v : move backward one page

  • m:< : move to beginning of file

  • m:> : move to end of file

  • c:a : move to beginning of line (left)

  • c:e : move to end of line (right)

  • c:n : move to next line (down)

  • c:p : move to previous line (up)

  • m:c:f : move forward one S-expression

  • m:c:b : move backward one S-expression

  • m:c:u : move up out of an S-expression

  • m:c:d : move down into a nested S-expression

  • m:c:space : select forward S-expression

  • m:c:p : match parentheses backward

  • m:c:left : move backwards to the nearest editor box

  • A-c:left : move backwards to the nearest editor box

  • m:c:right : move forward to the nearest editor box

  • A-c:right : move forward to the nearest editor box

  • m:c:up : move up out of an embedded editor

  • A-c:up : move up out of an embedded editor

  • m:c:down : move down into an embedded editor

  • A-c:down : move down into an embedded editor

  • c:c;c:z : move the cursor to the interactions window

  • c:F6 : move the cursor between different windows (usually the interactions and definitions windows, but also the search window and other editable portions of DrRacket). Also, search for “shift-focus” in the Show Active Keybindings menu’s window for more, platform-specific keybindings that have this functionality

3.3.2Editing OperationsπŸ”— i

  • c:_ : undo

  • c:+ : redo

  • c:x;u : undo

  • c:d : delete forward one character

  • c:h : delete backward one character

  • m:d : delete forward one word

  • m:delete : delete backward one word

  • c:k : delete forward to end of line

  • m:c:k : delete forward one S-expression

  • m:w : copy selection to clipboard

  • c:w : delete selection to clipboard (cut)

  • c:y : paste from clipboard (yank)

  • c:t : transpose characters

  • m:t : transpose words

  • m:c:t : transpose sexpressions

  • m:c:m : toggle dark green marking of matching parenthesis

  • m:c:k : cut complete sexpression

  • m:( : wrap selection in parentheses

  • m:[ : wrap selection in square brackets

  • m:{ : wrap selection in curly brackets

  • m:s:l : wrap selection in (lambda ()...) and put the insertion point in the argument list 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:cc;:l : wraps a let around the sexpression following the insertion point and puts a printf in at that point (useful for debugging).

  • m:o : toggle overwrite mode

  • c:x;r;a : Adjust nearby ASCII art rectangles (that use +, -, or |) to use Unicode characters.

    For example, if the insertion point is next to this rectangle:

    +-+

    | |

    +-+

    then the keystroke will turn it into this one:

    ╔═╗

    ║ ║

    ╚═╝

    Similarly, if the rectangle near the insertion point has mixed Unicode and ASCII, it will all be converted to the Unicode characters.

  • c:x;r;w : Widen the nearby ASCII art rectangles.

    For example, if the insertion point is just to the left of the middle line of this rectangle:

    ╔═╦══╗

    ║ ║ ║

    ╠═╬══╣

    ║ ║ ║

    ╚═╩══╝

    then the keystroke will turn it into this one:

    ╔══╦══╗

    ║ ║ ║

    ╠══╬══╣

    ║ ║ ║

    ╚══╩══╝

  • c:x;r;v : Make the nearby ASCII art rectangles taller.

    For example, if the insertion point is just above the the middle line of this rectangle:

    ╔══╦══╗

    ║ ║ ║

    ╠══╬══╣

    ║ ║ ║

    ║ ║ ║

    ╚══╩══╝

    then the keystroke will turn it into this one:

    ╔══╦══╗

    ║ ║ ║

    ║ ║ ║

    ╠══╬══╣

    ║ ║ ║

    ║ ║ ║

    ╚══╩══╝

  • c:x;r;c : Centers the contents of the current line inside the enclosing cell of the enclosing ASCII art rectangle.

  • c:x;r;o : Toggles the ASCII art rectangle editing mode. When the mode is enabled, key strokes that would normally break the rectangles instead enlarge them. Specifically:
    • Return and enter add a line to the enclosing rectangle and put the insertion point at the first column of the enclosing cell.

    • When in overwrite mode, if a key would overwrite one of the walls of the cell, the wall is first moved over to accomodate the new key

    • When not in overwrite mode, inserting a character will always widen the containing cell

3.3.3File OperationsπŸ”— i

  • c:x;c:s : save file

  • c:x;c:w : save file under new name

3.3.4SearchπŸ”— i

  • c:s : search for string forward

  • c:r : search for string backward

3.3.5EvaluationπŸ”— i

  • f5 : Run

3.3.6DocumentationπŸ”— i

  • f1 : Search in the documentation for the words near the insertion point

  • f2 : Reveal the signature box for the identifier at the insertion point (requires background check syntax to be enabled or normal check syntax to have been run).

3.3.7InteractionsπŸ”— i

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

  • m:h : Show the current expression history in a separate window

Also, in the interactions window, the return key is treated specially, in particular to determine if the expression that’s been typed at the prompt is ready to be evaluated or not. There are three cases:
  • When shift-return is typed: the expression is not submitted and instead a new line is started

  • When alt-return or control return is typed: the expression is submitted for evaluation

  • When return with no modified is typed: the language is consulted to determine which of the two previous actions makes the most sense. Typically the language’s parser is consulted to see if the expression looks complete. If so, the expression is submitted and, if not, a new line is started. (See also 'drracket:submit-predicate.)

3.3.8LaTeX and TeX inspired keybindingsπŸ”— i

  • c:\ m:\ c:x;l : 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:

    \Downarrow

    \nwarrow

    \downarrow

    \Rightarrow

    \rightarrow

    \rightharpoonup

    \leftharpoonup

    \rightharpoondown

    \leftharpoondown

    \rightleftharpoons

    \mapsto

    \searrow

    \swarrow

    \leftarrow

    \uparrow

    \Leftarrow

    \longrightarrow

    \Uparrow

    \Leftrightarrow

    \updownarrow

    \leftrightarrow

    \nearrow

    \Updownarrow

    \leadsto

    \aleph

    א

    \prime

    \emptyset

    \nabla

    \diamondsuit

    \spadesuit

    \clubsuit

    \heartsuit

    \sharp

    \flat

    \natural

    \surd

    \neg

    ¬

    \triangle

    \forall

    \all

    \exists

    \infty

    \circ

    \partial

    \alpha

    α

    \theta

    θ

    \tau

    τ

    \beta

    β

    \vartheta

    ϑ

    \pi

    π

    \upsilon

    υ

    \gamma

    γ

    \varpi

    ϖ

    \phi

    ϕ

    \delta

    δ

    \kappa

    κ

    \rho

    ρ

    \varphi

    φ

    \epsilon

    ϵ

    \lambda

    λ

    \varrho

    ϱ

    \chi

    χ

    \varepsilon

    ε

    \mu

    μ

    \sigma

    σ

    \psi

    ψ

    \zeta

    ζ

    \nu

    ν

    \varsigma

    ς

    \omega

    ω

    \eta

    η

    \xi

    ξ

    \iota

    ι

    \Gamma

    Γ

    \Lambda

    Λ

    \Sigma

    Σ

    \Psi

    Ψ

    \Delta

    Δ

    \Xi

    Ξ

    \Upsilon

    Υ

    \Omega

    Ω

    \Theta

    Θ

    \Pi

    Π

    \Phi

    Φ

    \pm

    ±

    \cap

    \diamond

    \lozenge

    \square

    \oplus

    \mp

    \cup

    \bigtriangleup

    \ominus

    \times

    ×

    \uplus

    \bigtriangledown

    \otimes

    \div

    ÷

    \sqcap

    \triangleright

    \oslash

    \ast

    \sqcup

    \vee

    \wedge

    \lor

    \land

    \lnot

    ¬

    \triangleleft

    \angle

    \odot

    \star

    \dagger

    \bullet

    \ddagger

    \wr

    \amalg

    ⨿

    \leq

    \geq

    \equiv

    \models

    \prec

    \succ

    \precdot

    \succdot

    \sim

    \perp

    \bot

    \top

    \preceq

    \succeq

    \simeq

    \ll

    \gg

    \guillemetleft

    «

    \guillemetright

    »

    \asymp

    \parallel

    \subset

    \supset

    \approx

    \bowtie

    \subseteq

    \supseteq

    \nsubseteq

    \subsetneq

    \cong

    \sqsubsetb

    \sqsupsetb

    \neq

    \smile

    \sqsubseteq

    \sqsupseteq

    \doteq

    \frown

    \in

    \ni

    \notin

    \propto

    \vdash

    \dashv

    \cdot

    ·

    \sum

    \prod

    \coprod

    \int

    \iint

    \iiint

    \oint

    \oiint

    \oiiint

    \sqrt

    \skull

    \smiley

    \blacksmiley

    \frownie

    \Re

    \Im

    \S

    §

    \l

    ł

    \newpage

    ^L

    \vdots

    \ddots

    \cdots

    \hdots

    \ldots

    \langle

    \rangle

    \amp

    &

    \invamp

    \multimap

    \rightlollipop

    \leftmultimap

    \multimapinv

    \leftlollipop

    Additionally, all of the digits, lowercase letters, and uppercase letters can be turned into blackboard bold characters with the shortcut \b followed by the character. For example, \bN turns into ℕ and \bZ turns into ℤ.

3.3.9Defining Custom ShortcutsπŸ”— i

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:

#lang s-exp framework/keybinding-lang

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:

(keybindingstring-exprproc-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"(λ (editorevt)(send editorinsert"!")))

Since the file contains plain Racket code, you can write keybindings files that use DrRacket’s Extension API. For example, the following file binds “control-t” and “control-=” to a execute the program and open a new tab respectively, as they were used before version 5.2.

#lang s-exp framework/keybinding-lang
(define modifiers
(map (λ (p)
(case p
[(ctl)"c:"][(cmd)"d:"][(altmeta)"~c:m:"]
[(shift)"s:"][(option)"a:"]))
(define-syntax-rule (frame-keykeycommand)
(keybinding
(string-append modifierskey)
(λ (edevt)
(when (is-a? edtext:basic<%>)
(define fr(send edget-top-level-window))
;note: fr could be #f
(when fr(send frcommand))))))
(frame-key"t"execute-callback)
(frame-key"="create-new-tab)

Another example, this file rebinds “control-w” to delete the word behind the insertion point, but it does it by setting a new key to be an existing keyboard shortcut. If you see a key in the Show Active Keybindings dialog (in the Keybindings submenu of the Edit menu), then you can use its name with the new keystroke you want, like this:

#lang s-exp framework/keybinding-lang
(define (rebindkeycommand)
(keybinding
key
(λ (edevt)
(send (send edget-keymap)call-function
commandedevt#t))))
(rebind"c:w""backward-kill-word")

This example shows how to bind a menu item (based on its name) to a particular key. The call at the end of the example binds “control-a” to the Run menu item.

#lang s-exp framework/keybinding-lang
(define (menu-bindkeymenu-item)
(keybinding
key
(λ (edevt)
(define canvas(send edget-canvas))
(when canvas
(define menu-bar(find-menu-barcanvas))
(when menu-bar
(define item(find-itemmenu-barmenu-item))
(when item
(define menu-evt
[event-type'menu]
[time-stamp
(send evtget-time-stamp)]))
(send itemcommandmenu-evt)))))))
(define/contract (find-menu-barc)
(let loop([cc])
(cond
[(is-a? cframe% )(send cget-menu-bar)]
[(is-a? carea<%> )(loop(send cget-parent))]
[else #f])))
(define/contract (find-itemmenu-barlabel)
(let loop([omenu-bar])
(cond
(and (equal? (send oget-plain-label)label)
o)]
(for/or ([i(in-list (send oget-items))])
(loopi))]
[else #f])))
(menu-bind"c:a""Run")

Note that DrRacket does not reload keybindings files automatically when you make changes, so you’ll need to restart DrRacket to see changes to the file.

3.3.10Sending Program Fragments to the REPLπŸ”— i

Users comfortable with Emacs and the conventional Lisp/Scheme-style of interaction with an “inferior process” commonly request keybindings in DrRacket that send program fragments to be evaluated at the prompt. This style of interaction is fraught with difficulty, especially for beginners, and so DrRacket, by default, does not support it. Instead, clicking DrRacket’s “Run” button starts with a clean slate and sends the entire contents of the definitions window, ensuring that the state in the REPL matches what you would expect by reading the source code of the program.

Based on years of experience with Emacs modes, some of the authors consider this mode of interaction also appropriate for experienced programmers. Indeed, they go through great effort to mimic this behavior in Emacs.

That said, some people may wish to use such incremental keystroke modes anyway. Therefore the remainder of this section illustrates how to add such an incremental mode for your personal use with an example keybindings file. Specifically, the file shows how to add the ability to send expressions piecemeal to the interactions window. It also demonstrates how to pull together a bunch of pieces of DrRacket’s implementation and its libraries to implement keystrokes.

#lang s-exp framework/keybinding-lang
 
(require drracket/tool-lib)
 
(module testracket/base)
 
(keybinding"c:c;c:e"(lambda (edevt)(send-toplevel-formed#f)))
(keybinding"c:c;c:r"(lambda (edevt)(send-selectioned#f)))
(keybinding"c:c;~c:m:e"(lambda (edevt)(send-toplevel-formed#t)))
(keybinding"c:c;~c:m:r"(lambda (edevt)(send-selectioned#t)))
 
(define/contract (send-toplevel-formdefsshift-focus?)
(define sp(send defsget-start-position))
(when (= sp(send defsget-end-position))
(cond
[(send defsfind-up-sexpsp)
;;weareinsidesometop-levelexpression;
;;findtheenclosingexpression
(let loop([possp])
(define next-up(send defsfind-up-sexppos))
(cond
[next-up(loopnext-up)]
[else
(send-range-to-repldefs
pos
(send defsget-forward-sexppos)
shift-focus?)]))]
[else
;;weareatthetop-level
(define fw(send defsget-forward-sexpsp))
(define bw(send defsget-backward-sexpsp))
(cond
[(and (not fw)(not bw))
;;noexpressionsinthefile,giveup
(void )]
[(not fw)
;;noexpressionaftertheinsertionpoint;
;;sendtheonebeforeit
(send-range-to-repldefs
bw
(send defsget-forward-sexpbw)
shift-focus?)]
[else
;;sendtheexpressionaftertheinsertionpoint
(send-range-to-repldefs
(send defsget-backward-sexpfw)
fw
shift-focus?)])]))))
(define/contract (send-selectiondefsshift-focus?)
(send-range-to-repldefs
(send defsget-start-position)
(send defsget-end-position)
shift-focus?)))
 
(define/contract (send-range-to-repldefsstartendshift-focus?)
[end(start)(and/c exact-positive-integer? (>=/c start))]
[shift-focus?boolean? ])
any )
(unless (= startend);;don'tsendemptyregions
(define ints(send (send defsget-tab)get-ints))
(define frame(send (send defsget-tab)get-frame))
;;copytheexpressionovertotheinteractionswindow
(send defsmove/copy-to-edit
intsstartend
(send intslast-position)
#:try-to-move?#f)
;;eraseanytrailingwhitespace
(let loop()
(define last-pos(- (send intslast-position)1))
(when (last-pos.> .0)
(define last-char(send intsget-characterlast-pos))
(when (char-whitespace? last-char)
(send intsdeletelast-pos(+ last-pos1))
(loop))))
;;putbackasinglenewline
(send intsinsert
"\n"
(send intslast-position)
(send intslast-position))
;;makesuretheinteractionsisvisible
;;andrunthesubmittedexpression
(send frameensure-rep-shownints)
(when shift-focus?(send (send intsget-canvas)focus))
(send intsdo-submission)))
 

Others may wish to use the above example to invent other keystrokes for making work in DrRacket convenient.

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /