Last active
March 11, 2024 21:14
-
-
Save PiotrCzapla/d4ea5d48c9cef7262da951b03edef981 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Nbdev in VSCode" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"github issue covering this topic:\n", | |
"https://github.com/microsoft/vscode-jupyter/issues/4376\n", | |
"Current keybindings for notebooks where extracted to another extension (ms-toolsai.jupyter-keymap), \n", | |
"and can be found here: https://github.com/microsoft/vscode-jupyter-keymap/blob/main/package.json\n", | |
"\n", | |
"\n", | |
"To support jupyter shortcuts make sure that you have this extension installed.(https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter-keymap)\n", | |
"https://github.com/Microsoft/vscode-jupyter-keymap\n", | |
"\n", | |
"\n", | |
"## Command mode Shortcuts\n", | |
"\n", | |
"### Navigation\n", | |
"- `j` / `k` to move up/down\n", | |
"- `g` + `g` to go to the top of the notebook\n", | |
"- `shift` + `g` to go to the bottom of the notebook\n", | |
"- `f` - find\n", | |
"\n", | |
"### Outline navigaton shortcuts\n", | |
"- `cmd` + `shift` + `.` - takes you to breadcrumbs, then `up`/`down` lets you navigate through outline\n", | |
"- `cmd` + `shift` + `o` - runs go to symbol dialog, which shows outline in notebooks and let you jump to random cell\n", | |
"\n", | |
"### Execute (works in edit mode too)\n", | |
"- `shift` + `enter` / `alt` + `enter` to run cell and (move / create) next cell \n", | |
"- `cmd` + `enter` to run cell and stay in the same cell\n", | |
"\n", | |
"### Manipulation (cut/copy/paste/undo)\n", | |
"- `a` to add cell above\n", | |
"- `b` to add cell below\n", | |
"- `d` + `d` | `x` to cut cell\n", | |
"- `c` to copy\n", | |
"- `v` to paste below,\n", | |
"- `shift` + `v` - paste above ❌ does not work\n", | |
"- `shift` + `j` / `k` ❎ works only after adding keybindings, without use shift up/down\n", | |
"- `alt` + `up` / `down` to move cell up/down\n", | |
"\n", | |
"### Save / undo / redo\n", | |
"- `s` - save\n", | |
"- `z` or `cmd` + `z` to undo (`u` does not work)\n", | |
"- to redo use `cmd` + `shift` + `z` it works now\n", | |
"\n", | |
"### Changing cell types \n", | |
"- `m` to change cell to markdown \n", | |
"- `y` to change cell to code \n", | |
"\n", | |
"## Edit mode shortcuts\n", | |
"### Split & merge \n", | |
"- `ctrl` + `shift`+`-` - in edit mode splits cell at the cursor , note it is `ctrl` on both mac and windows\n", | |
"- `ctrl` + `alt` + `j` - join with the next cell, (if multiple selected joins all with the next cell)\n", | |
"- `ctrl` + `shift` + `alt` + `j` - join with the next cell, (if multiple selected joins all with the next cell)\n", | |
"- `shift` + `m` - merge cells, ❌ but it does not work. I don't see an option/command to merge selected cells. Check implementation: (https://github.com/microsoft/vscode/blob/main/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.ts)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"- `https://marketplace.visualstudio.com/items?itemName=bierner.markdown-checkbox` - let you view checkboxes in markdown and in notebooks" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Workaround for missing NBDEV workflow in VSCode\n", | |
"\n", | |
"### Key bindings to solve some of the issues\n", | |
"```json\n", | |
"{\n", | |
" \"key\": \"shift+j\", // so it works like shift+down\n", | |
" \"command\": \"list.expandSelectionDown\",\n", | |
" \"when\": \"listFocus && listSupportsMultiselect && !inputFocus\"\n", | |
"},\n", | |
"{\n", | |
" \"key\": \"shift+k\", // so it works like shift+up\n", | |
" \"command\": \"list.expandSelectionUp\",\n", | |
" \"when\": \"listFocus && listSupportsMultiselect && !inputFocus\"\n", | |
"}\n", | |
"```\n", | |
"\n", | |
"\n", | |
"### Notebook clean up on save is not supported yet. \n", | |
"\n", | |
"> As a workaround we need to fire `nbdev_clean`, before commiting. \n", | |
"```py\n", | |
"def nbdev_clean():\n", | |
" fn = globals().get('__vsc_ipynb_file__', None)\n", | |
" if fn is None: return\n", | |
" import nbdev.clean\n", | |
" nbdev.clean.nbdev_clean(fn)\n", | |
"nbdev_clean() \n", | |
"```\n", | |
"\n", | |
"The VSCode do not expose save events yet see\n", | |
"- [ Improve workspace API or Notebook lifecycle to support (at least) saving events ]( https://github.com/microsoft/vscode/issues/130799 )\n", | |
"- [ Stack question ]( https://stackoverflow.com/questions/72103359/format-a-jupyter-notebook-on-save-in-vscode )\n", | |
"- [ Format on save for a notebook ]( https://github.com/microsoft/vscode/issues/120432 )\n", | |
"- [ Settings for controlling if outputs should be saved to disk ]( https://github.com/microsoft/vscode/issues/124551 )\n", | |
"### No autosave by default so nbdev_export does not work\n", | |
"Workaround: enable autosave in vscode `File: Toggle Auto Save` then you can run `import nbdev; nbdev.export()` without issues." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3.9.6 64-bit", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.6" | |
}, | |
"orig_nbformat": 4, | |
"vscode": { | |
"interpreter": { | |
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting! Watching this space