命令与特殊键
所有 REPL 实例都支持以下特殊命令:
.break: 当在输入多行表达式的过程中,输入.break命令(或按 Ctrl+C)以中止该表达式的进一步输入或处理。.clear: 将 REPLcontext重置为空对象并清除任何输入的多行表达式。.exit: 关闭 I/O 流,导致 REPL 退出。.help: 显示此特殊命令列表。.save: 将当前 REPL 会话保存到文件:> .save ./file/to/save.js.load: 将文件加载到当前 REPL 会话中。> .load ./file/to/load.js.editor: 进入编辑器模式(Ctrl+D 完成,Ctrl+C 取消)。
> .editor
// 进入编辑器模式(^D 完成,^C 取消)
function welcome(name) {
return `Hello ${name}!`;
}
welcome('Node.js User');
// ^D
'Hello Node.js User!'
>REPL 中的以下组合键具有这些特殊效果:
- Ctrl+C: 按下一次,效果与
.break命令相同。 当在空白行上按两次时,效果与.exit命令相同。 - Ctrl+D: 与
.exit命令效果相同。 - 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, enter the.breakcommand (or press Ctrl+C) to abort further input or processing of that expression..clear: Resets the REPLcontextto 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
.breakcommand. When pressed twice on a blank line, has the same effect as the.exitcommand. - Ctrl+D: Has the same effect as the
.exitcommand. - 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.