命令与特殊键
所有 REPL 实例都支持以下特殊命令:
.break
:.clear
: 将 REPLcontext
重置为空对象并清除任何输入的多行表达式。.exit
: 关闭 I/O 流,导致 REPL 退出。.help
: 显示此特殊命令列表。.save
: 将当前 REPL 会话保存到文件:> .save ./file/to/save.js
.load
: 将文件加载到当前 REPL 会话中。> .load ./file/to/load.js
.editor
:
> .editor
// 进入编辑器模式(^D 完成,^C 取消)
function welcome(name) {
return `Hello ${name}!`;
}
welcome('Node.js User');
// ^D
'Hello Node.js User!'
>
REPL 中的以下组合键具有这些特殊效果:
<ctrl>-C
: 当在空白行上按两次时,效果与.exit
命令相同。<ctrl>-D
:<tab>
: 当在输入其他输入时按下时,显示相关的自动完成选项。
有关反向搜索的键绑定,请参阅 reverse-i-search
。
对于所有其他键绑定,请参阅 TTY 键绑定。
The following special commands are supported by all REPL instances:
.break
: When in the process of inputting a multi-line expression, entering the.break
command (or pressing the<ctrl>-C
key combination) will abort further input or processing of that expression..clear
: Resets the REPLcontext
to an empty object and clears any multi-line expression being input..exit
: Close the I/O stream, causing the REPL to exit..help
: Show this list of special commands..save
: Save the current REPL session to a file:> .save ./file/to/save.js
.load
: Load a file into the current REPL session.> .load ./file/to/load.js
.editor
: Enter editor mode (<ctrl>-D
to finish,<ctrl>-C
to cancel).
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function welcome(name) {
return `Hello ${name}!`;
}
welcome('Node.js User');
// ^D
'Hello Node.js User!'
>
The following key combinations in the REPL have these special effects:
<ctrl>-C
: When pressed once, has the same effect as the.break
command. When pressed twice on a blank line, has the same effect as the.exit
command.<ctrl>-D
: Has the same effect as the.exit
command.<tab>
: When pressed on a blank line, displays global and local (scope) variables. When pressed while entering other input, displays relevant autocompletion options.
For key bindings related to the reverse-i-search, see reverse-i-search
.
For all other key bindings, see TTY keybindings.