菜鸟笔记
提升您的技术认知

Jupyter Notebook基础(5)快捷键说明、快捷键设置

Jupyter Notebook快捷键说明

Jupyter Notebook编辑器有两种不同的键盘输入模式。即命令模式和编辑模式,这与 Vim 有些类似。在编辑模式下,可以在单元格中输入代码或文本,此时单元格被绿色的框线包围,且命令模式下的快捷键不生效。在命令模式下,可以用快捷键命令运行单元格,移动单元格,切换单元格编辑状态等等,此时的单元格被灰色的框线包围,且编辑模式下的快捷键不生效。

命令模式(按 Esc 生效)

快捷键 说明1 说明2
F find and replace 查找并且替换
Ctrl-Shift-F open the command palette 打开命令配置
Ctrl-Shift-P open the command palette 打开命令配置
Enter enter edit mode 进入编辑模式
P open the command palette 打开命令配置
Shift-Enter run cell, select below 运行代码块, 选择下面的代码块
Ctrl-Enter run selected cells 运行选中的代码块
Alt-Enter run cell and insert below 运行代码块并且在下面插入代码块
Y change cell to code 把代码块变成代码
M change cell to markdown 把代码块变成 Markdown
R change cell to raw 清除代码块格式
1 change cell to heading 1 把代码块变成标题 1
2 change cell to heading 2 把代码块变成标题 2
3 change cell to heading 3 把代码块变成标题 3
4 change cell to heading 4 把代码块变成标题 4
5 change cell to heading 5 把代码块变成标题 5
6 change cell to heading 6 把代码块变成标题 6
K select cell above 选择上面的代码块
select cell above 选择上面的代码块
select cell below 选择下面的代码块
J select cell below 选择下面的代码块
Shift-K extend selected cells above 扩展上面选择的代码块
Shift-上 extend selected cells above 扩展上面选择的代码块
Shift-下 extend selected cells below 扩展下面选择的代码块
Shift-J extend selected cells below 扩展下面选择的代码块
Ctrl-A select all cells select all cells
A insert cell above 在上面插入代码块
B insert cell below 在下面插入代码块
X cut selected cells 剪切选择的代码块
C copy selected cells 复制选择的代码块
Shift-V paste cells above 粘贴到上面
V paste cells below 粘贴到下面
Z undo cell deletion 撤销删除
D,D delete selected cells 删除选中单元格
Shift-M merge selected cells, or current cell with cell below if only one cell is selected 合并选中单元格, 如果只有一个单元格被选中
Ctrl-S Save and Checkpoint 保存并建立检查点
S Save and Checkpoint 保存并建立检查点
L toggle line numbers 切换行号
O toggle output of selected cells 切换选定单元格的输出
Shift-O toggle output scrolling of selected cells 切换选中单元格的输出滚动
H show keyboard shortcuts 显示键盘快捷键
I,I interrupt the kernel 中断内核
0,0 restart the kernel (with dialog) 重启内核(带确认对话框)
Esc close the pager 关闭分页器
Q close the pager 关闭分页器
Shift-L toggles line numbers in all cells, and persist the setting 在所有单元格中切换行号,并保持设置
Shift-空格 scroll notebook up 向上滚动
空格 scroll notebook down 向下滚动

编辑模式(按 Enter 生效)

快捷键 说明1 说明2
Tab code completion or indent 代码补全或缩进
Shift-Tab tooltip 工具提示
Ctrl-] indent 缩进
Ctrl-[ dedent 取消缩进
Ctrl-A select all 全选
Ctrl-Z undo 撤销
Ctrl-/ comment 注释
Ctrl-D delete whole line 删除整行
Ctrl-U undo selection 撤销选择
Insert toggle overwrite flag 切换重写标志
Ctrl-Home go to cell start 跳到单元格起始处
Ctrl-Up go to cell start 跳到单元格起始处
Ctrl-End go to cell end 跳到单元格最后
Ctrl-Down go to cell end 跳到单元格最后
Ctrl-Left go one word left 往左跳一个单词
Ctrl-Right go one word right 往右跳一个单词
Ctrl-Backspace delete word before 删除前面的单词
Ctrl-Delete delete word after 删除后面的单词
Ctrl-Y redo 重做
Alt-U redo selection 重新选择
Ctrl-M enter command mode 进入命令行模式
Ctrl-Shift-F open the command palette 打开命令配置
Ctrl-Shift-P open the command palette 打开命令配置
Esc enter command mode 进入命令行模式
Shift-Enter run cell, select below 运行代码块, 选择下面的代码块
Ctrl-Enter run selected cells 运行选中的代码块
Alt-Enter run cell and insert below 运行代码块并且在下面插入代码块
Ctrl-Shift-Minus split cell at cursor 在光标处分割单元格
Ctrl-S Save and Checkpoint 保存并建立检查点
Down move cursor down 光标下移
Up move cursor up 光标上移