Skip to content

Commit c72fff6

Browse files
HarshithaKPcodebytere
authored andcommitted
doc: document readline key bindings
This documents all readline key bindings. It is a rework of #20825 PR-URL: #31256 Fixes: #20814 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 476e919 commit c72fff6

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

Diff for: doc/api/readline.md

+128-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ added: v0.1.98
293293

294294
The `rl.write()` method will write either `data` or a key sequence identified
295295
by `key` to the `output`. The `key` argument is supported only if `output` is
296-
a [TTY][] text terminal.
296+
a [TTY][] text terminal. See [TTY keybindings][] for a list of key
297+
combinations.
297298

298299
If `key` is specified, `data` is ignored.
299300

@@ -722,6 +723,131 @@ const { createInterface } = require('readline');
722723
})();
723724
```
724725

726+
## TTY keybindings
727+
728+
<table>
729+
<tr>
730+
<th>Keybindings</th>
731+
<th>Description</th>
732+
<th>Notes</th>
733+
</tr>
734+
<tr>
735+
<td><code>ctrl</code> + <code>shift</code> + <code>backspace</code></td>
736+
<td>Delete line left</td>
737+
<td>Doesn't work on Linux, Mac and Windows</td>
738+
</tr>
739+
<tr>
740+
<td><code>ctrl</code> + <code>shift</code> + <code>delete</code></td>
741+
<td>Delete line right</td>
742+
<td>Doesn't work on Linux and Mac</td>
743+
</tr>
744+
<tr>
745+
<td><code>ctrl</code> + <code>c</code></td>
746+
<td>Emit <code>SIGINT</code> or close the readline instance</td>
747+
<td></td>
748+
</tr>
749+
<tr>
750+
<td><code>ctrl</code> + <code>h</code></td>
751+
<td>Delete left</td>
752+
<td></td>
753+
</tr>
754+
<tr>
755+
<td><code>ctrl</code> + <code>d</code></td>
756+
<td>Delete right or close the readline instance in case the current line is empty / EOF</td>
757+
<td>Doesn't work on Windows</td>
758+
</tr>
759+
<tr>
760+
<td><code>ctrl</code> + <code>u</code></td>
761+
<td>Delete from the current position to the line start</td>
762+
<td></td>
763+
</tr>
764+
<tr>
765+
<td><code>ctrl</code> + <code>k</code></td>
766+
<td>Delete from the current position to the end of line</td>
767+
<td></td>
768+
</tr>
769+
<tr>
770+
<td><code>ctrl</code> + <code>a</code></td>
771+
<td>Go to start of line</td>
772+
<td></td>
773+
</tr>
774+
<tr>
775+
<td><code>ctrl</code> + <code>e</code></td>
776+
<td>Go to to end of line</td>
777+
<td></td>
778+
</tr>
779+
<tr>
780+
<td><code>ctrl</code> + <code>b</code></td>
781+
<td>Back one character</td>
782+
<td></td>
783+
</tr>
784+
<tr>
785+
<td><code>ctrl</code> + <code>f</code></td>
786+
<td>Forward one character</td>
787+
<td></td>
788+
</tr>
789+
<tr>
790+
<td><code>ctrl</code> + <code>l</code></td>
791+
<td>Clear screen</td>
792+
<td></td>
793+
</tr>
794+
<tr>
795+
<td><code>ctrl</code> + <code>n</code></td>
796+
<td>Next history item</td>
797+
<td></td>
798+
</tr>
799+
<tr>
800+
<td><code>ctrl</code> + <code>p</code></td>
801+
<td>Previous history item</td>
802+
<td></td>
803+
</tr>
804+
<tr>
805+
<td><code>ctrl</code> + <code>z</code></td>
806+
<td>Moves running process into background. Type
807+
<code>fg</code> and press <code>enter</code>
808+
to return.</td>
809+
<td>Doesn't work on Windows</td>
810+
</tr>
811+
<tr>
812+
<td><code>ctrl</code> + <code>w</code> or <code>ctrl</code>
813+
+ <code>backspace</code></td>
814+
<td>Delete backwards to a word boundary</td>
815+
<td><code>ctrl</code> + <code>backspace</code> Doesn't
816+
work as expected on Windows</td>
817+
</tr>
818+
<tr>
819+
<td><code>ctrl</code> + <code>delete</code></td>
820+
<td>Delete forward to a word boundary</td>
821+
<td>Doesn't work on Mac</td>
822+
</tr>
823+
<tr>
824+
<td><code>ctrl</code> + <code>left</code> or
825+
<code>meta</code> + <code>b</code></td>
826+
<td>Word left</td>
827+
<td><code>ctrl</code> + <code>left</code> Doesn't work
828+
on Mac</td>
829+
</tr>
830+
<tr>
831+
<td><code>ctrl</code> + <code>right</code> or
832+
<code>meta</code> + <code>f</code></td>
833+
<td>Word right</td>
834+
<td><code>ctrl</code> + <code>right</code> Doesn't work
835+
on Mac</td>
836+
</tr>
837+
<tr>
838+
<td><code>meta</code> + <code>d</code> or <code>meta</code>
839+
+ <code>delete</code></td>
840+
<td>Delete word right</td>
841+
<td><code>meta</code> + <code>delete</code> Doesn't work
842+
on windows</td>
843+
</tr>
844+
<tr>
845+
<td><code>meta</code> + <code>backspace</code></td>
846+
<td>Delete word left</td>
847+
<td>Doesn't work on Mac</td>
848+
</tr>
849+
</table>
850+
725851
[`'SIGCONT'`]: readline.html#readline_event_sigcont
726852
[`'SIGTSTP'`]: readline.html#readline_event_sigtstp
727853
[`'line'`]: #readline_event_line
@@ -731,5 +857,6 @@ const { createInterface } = require('readline');
731857
[`rl.close()`]: #readline_rl_close
732858
[Readable]: stream.html#stream_readable_streams
733859
[TTY]: tty.html
860+
[TTY keybindings]: #readline_tty_keybindings
734861
[Writable]: stream.html#stream_writable_streams
735862
[reading files]: #readline_example_read_file_stream_line_by_line

Diff for: doc/api/repl.md

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ The following key combinations in the REPL have these special effects:
6666
variables. When pressed while entering other input, displays relevant
6767
autocompletion options.
6868

69+
For key bindings related to the reverse-i-search, see [`reverse-i-search`][].
70+
For all other key bindings, see [TTY keybindings][].
71+
6972
### Default Evaluation
7073

7174
By default, all instances of [`repl.REPLServer`][] use an evaluation function
@@ -709,5 +712,7 @@ For an example of running a REPL instance over [curl(1)][], see:
709712
[`repl.ReplServer`]: #repl_class_replserver
710713
[`repl.start()`]: #repl_repl_start_options
711714
[`util.inspect()`]: util.html#util_util_inspect_object_options
715+
[`reverse-i-search`]: #repl_reverse_i_search
716+
[TTY keybindings]: readline.html#readline_tty_keybindings
712717
[curl(1)]: https://curl.haxx.se/docs/manpage.html
713718
[stream]: stream.html

0 commit comments

Comments
 (0)