<span>Jupyter Notebook 快捷键和技巧</span>
Jupyter Notebook 有两种键盘输入模式。
编辑模式,允许你往单元中键入代码或文本,这时的单元框线是绿色的。
命令模式,键盘输入运行程序命令;这时的单元框线是蓝色。
命令模式 (按键 Esc 开启)
- Enter : 转入编辑模式
- Shift-Enter : 运行本单元,选中下个单元
- Ctrl-Enter : 运行本单元
- Alt-Enter : 运行本单元,在其下插入新单元
- Y : 单元转入代码状态
- M :单元转入markdown状态
- R : 单元转入raw状态
- 1 : 设定 1 级标题
- 2 : 设定 2 级标题
- 3 : 设定 3 级标题
- 4 : 设定 4 级标题
- 5 : 设定 5 级标题
- 6 : 设定 6 级标题
- Up : 选中上方单元
- K : 选中上方单元
- Down : 选中下方单元
- J : 选中下方单元
- Shift-K : 扩大选中上方单元
- Shift-J : 扩大选中下方单元
- A : 在上方插入新单元
- B : 在下方插入新单元
- X : 剪切选中的单元
- C : 复制选中的单元
- Shift-V : 粘贴到上方单元
- V : 粘贴到下方单元
- Z : 恢复删除的最后一个单元
- D,D : 删除选中的单元
- Shift-M : 合并选中的单元
- Ctrl-S : 文件存盘
- S : 文件存盘
- L : 转换行号
- O : 转换输出
- Shift-O : 转换输出滚动
- Esc : 关闭页面
- Q : 关闭页面
- H : 显示快捷键帮助
- I,I : 中断Notebook内核
- 0,0 : 重启Notebook内核
- Shift : 忽略
- Shift-Space : 向上滚动
- Space : 向下滚动
编辑模式 ( Enter 键启动)
- Tab : 代码补全或缩进
- Shift-Tab : 提示
- Ctrl-] : 缩进
- Ctrl-[ : 解除缩进
- Ctrl-A : 全选
- Ctrl-Z : 复原
- Ctrl-Shift-Z : 再做
- Ctrl-Y : 再做
- Ctrl-Home : 跳到单元开头
- Ctrl-Up : 跳到单元开头
- Ctrl-End : 跳到单元末尾
- Ctrl-Down : 跳到单元末尾
- Ctrl-Left : 跳到左边一个字首
- Ctrl-Right : 跳到右边一个字首
- Ctrl-Backspace : 删除前面一个字
- Ctrl-Delete : 删除后面一个字
- Esc : 进入命令模式
- Ctrl-M : 进入命令模式
- Shift-Enter : 运行本单元,选中下一单元
- Ctrl-Enter : 运行本单元
- Alt-Enter : 运行本单元,在下面插入一单元
- Ctrl-Shift-- : 分割单元
- Ctrl-Shift-Subtract : 分割单元
- Ctrl-S : 文件存盘
- Shift : 忽略
- Up : 光标上移或转入上一单元
- Down :光标下移或转入下一单元
HELP可以帮助我们直接进入对应的官方文档
Keyboard Shortcuts 原文档
The Jupyter Notebook has two different keyboard input modes. Edit mode allows you to type code or text into a cell and is indicated by a green cell border. Command mode binds the keyboard to notebook level commands and is indicated by a grey cell border with a blue left margin.
Command Mode (press <kbd>Esc</kbd> to enable)<button class="btn btn-xs btn-default pull-right" title="edit command-mode keyboard shortcuts">Edit Shortcuts</button>
<kbd>F</kbd>: find and replace
<kbd>Ctrl-Shift-F</kbd>: open the command palette
<kbd>Ctrl-Shift-P</kbd>: open the command palette
<kbd>Enter</kbd>: enter edit mode
<kbd>P</kbd>: open the command palette
<kbd>Shift-Enter</kbd>: run cell, select below
<kbd>Ctrl-Enter</kbd>: run selected cells
<kbd>Alt-Enter</kbd>: run cell and insert below
<kbd>Y</kbd>: change cell to code
<kbd>M</kbd>: change cell to markdown
<kbd>R</kbd>: change cell to raw
<kbd>1</kbd>: change cell to heading 1
<kbd>2</kbd>: change cell to heading 2
<kbd>3</kbd>: change cell to heading 3
<kbd>4</kbd>: change cell to heading 4
<kbd>5</kbd>: change cell to heading 5
<kbd>6</kbd>: change cell to heading 6
<kbd>K</kbd>: select cell above
<kbd>Up</kbd>: select cell above
<kbd>Down</kbd>: select cell below
<kbd>J</kbd>: select cell below
<kbd>Shift-K</kbd>: extend selected cells above
<kbd>Shift-Up</kbd>: extend selected cells above
<kbd>Shift-Down</kbd>: extend selected cells below
<kbd>Shift-J</kbd>: extend selected cells below
<kbd>A</kbd>: insert cell above
<kbd>B</kbd>: insert cell below
<kbd>X</kbd>: cut selected cells
<kbd>C</kbd>: copy selected cells
<kbd>Shift-V</kbd>: paste cells above
<kbd>V</kbd>: paste cells below
<kbd>Z</kbd>: undo cell deletion
<kbd>D</kbd>,<kbd>D</kbd>: delete selected cells
<kbd>Shift-M</kbd>: merge selected cells, or current cell with cell below if only one cell is selected
<kbd>Ctrl-S</kbd>: Save and Checkpoint
<kbd>S</kbd>: Save and Checkpoint
<kbd>L</kbd>: toggle line numbers
<kbd>O</kbd>: toggle output of selected cells
<kbd>Shift-O</kbd>: toggle output scrolling of selected cells
<kbd>H</kbd>: show keyboard shortcuts
<kbd>I</kbd>,<kbd>I</kbd>: interrupt the kernel
<kbd>0</kbd>,<kbd>0</kbd>: restart the kernel (with dialog)
<kbd>Esc</kbd>: close the pager
<kbd>Q</kbd>: close the pager
<kbd>Shift-L</kbd>: toggles line numbers in all cells, and persist the setting
<kbd>Shift-Space</kbd>: scroll notebook up
<kbd>Space</kbd>: scroll notebook down
Edit Mode (press <kbd>Enter</kbd> to enable)
<kbd>Tab</kbd>: code completion or indent
<kbd>Shift-Tab</kbd>: tooltip
<kbd>Ctrl-]</kbd>: indent
<kbd>Ctrl-[</kbd>: dedent
<kbd>Ctrl-A</kbd>: select all
<kbd>Ctrl-Z</kbd>: undo
<kbd>Ctrl-/</kbd>: comment
<kbd>Ctrl-D</kbd>: delete whole line
<kbd>Ctrl-U</kbd>: undo selection
<kbd>Insert</kbd>: toggle overwrite flag
<kbd>Ctrl-Home</kbd>: go to cell start
<kbd>Ctrl-Up</kbd>: go to cell start
<kbd>Ctrl-End</kbd>: go to cell end
<kbd>Ctrl-Down</kbd>: go to cell end
<kbd>Ctrl-Left</kbd>: go one word left
<kbd>Ctrl-Right</kbd>: go one word right
<kbd>Ctrl-Backspace</kbd>: delete word before
<kbd>Ctrl-Delete</kbd>: delete word after
<kbd>Ctrl-Y</kbd>: redo
<kbd>Alt-U</kbd>: redo selection
<kbd>Ctrl-M</kbd>: enter command mode
<kbd>Ctrl-Shift-F</kbd>: open the command palette
<kbd>Ctrl-Shift-P</kbd>: open the command palette
<kbd>Esc</kbd>: enter command mode
<kbd>Shift-Enter</kbd>: run cell, select below
<kbd>Ctrl-Enter</kbd>: run selected cells
<kbd>Alt-Enter</kbd>: run cell and insert below
<kbd>Ctrl-Shift-Minus</kbd>: split cell at cursor
<kbd>Ctrl-S</kbd>: Save and Checkpoint
<kbd>Down</kbd>: move cursor down
<kbd>Up</kbd>: move cursor up