命令和特殊键
¥Commands and special keys
所有 REPL 实例都支持以下特殊命令:
¥The following special commands are supported by all REPL instances:
-
.break
:在输入多行表达式的过程中,输入.break
命令(或按 Ctrl+C)可中止对该表达式的进一步输入或处理。¥
.break
: When in the process of inputting a multi-line expression, enter the.break
command (or press Ctrl+C) to abort further input or processing of that expression. -
.clear
:将 REPLcontext
重置为空对象并清除任何输入的多行表达式。¥
.clear
: Resets the REPLcontext
to an empty object and clears any multi-line expression being input. -
.exit
:关闭 I/O 流,导致 REPL 退出。¥
.exit
: Close the I/O stream, causing the REPL to exit. -
.help
:显示此特殊命令列表。¥
.help
: Show this list of special commands. -
.save
:将当前 REPL 会话保存到一个文件中:> .save ./file/to/save.js
¥
.save
: Save the current REPL session to a file:> .save ./file/to/save.js
-
.load
:将文件加载到当前 REPL 会话中。> .load ./file/to/load.js
¥
.load
: Load a file into the current REPL session.> .load ./file/to/load.js
-
.editor
:进入编辑模式(Ctrl+D 完成,Ctrl+C 取消)。¥
.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!'
>
REPL 中的以下组合键具有这些特殊效果:
¥The following key combinations in the REPL have these special effects:
-
Ctrl+C:按一次时,与
.break
命令具有相同的效果。当在空白行上按两次时,效果与.exit
命令相同。¥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:与
.exit
命令具有相同的效果。¥Ctrl+D: Has the same effect as the
.exit
command. -
Tab:在空白行上按下时,显示全局和局部(作用域)变量。当在输入其他输入时按下时,显示相关的自动补齐选项。
¥Tab: When pressed on a blank line, displays global and local (scope) variables. When pressed while entering other input, displays relevant autocompletion options.
有关反向搜索的键绑定,请参阅 reverse-i-search
。对于所有其他键绑定,请参阅 TTY 键绑定。
¥For key bindings related to the reverse-i-search, see reverse-i-search
.
For all other key bindings, see TTY keybindings.