Skip to content

Instantly share code, notes, and snippets.

@pizofreude
Created March 5, 2025 11:28
Show Gist options
  • Save pizofreude/47740403532da9c7e61fdd152ef52d87 to your computer and use it in GitHub Desktop.
Save pizofreude/47740403532da9c7e61fdd152ef52d87 to your computer and use it in GitHub Desktop.
Jupyter Notebook Keyboard Shortcuts for Windows and Linux

Jupyter Notebook Keyboard Shortcuts for Windows and Linux

General Shortcuts

  • Enter: Enter edit mode
  • Esc: Enter command mode
  • Shift + Enter: Run cell, select below
  • Ctrl + Enter: Run cell
  • Alt + Enter: Run cell, insert below
  • Ctrl + S: Save and checkpoint

Command Mode Shortcuts (press Esc to enable)

  • Up: Select cell above
  • Down: Select cell below
  • A: Insert cell above
  • B: Insert cell below
  • X: Cut selected cell
  • C: Copy selected cell
  • Shift + V: Paste cell above
  • V: Paste cell below
  • Z: Undo cell deletion
  • D, D: Delete selected cell
  • Shift + M: Merge selected cells
  • Y: Change cell to code
  • M: Change cell to markdown
  • R: Change cell to raw
  • 1: Change cell to heading 1
  • 2: Change cell to heading 2
  • 3: Change cell to heading 3
  • 4: Change cell to heading 4
  • 5: Change cell to heading 5
  • 6: Change cell to heading 6
  • 0, 0: Restart the kernel (with dialog)
  • I, I: Interrupt the kernel
  • Q: Close the pager
  • H: Show keyboard shortcuts
  • P: Open the command palette

Edit Mode Shortcuts (press Enter to enable)

  • Tab: Code completion or indent
  • Shift + Tab: Tooltip
  • Ctrl + ]: Indent
  • Ctrl + [: Dedent
  • Ctrl + A: Select all
  • Ctrl + Z: Undo
  • Ctrl + Shift + Z: Redo
  • Ctrl + Y: Redo
  • Ctrl + Home: Go to cell start
  • Ctrl + End: Go to cell end
  • Ctrl + Left: Move cursor left one word
  • Ctrl + Right: Move cursor right one word
  • Ctrl + Shift + P: Open the command palette
  • Esc: Command mode
  • Ctrl + M: Command mode
  • Shift + Enter: Run cell, select below
  • Ctrl + Enter: Run cell
  • Alt + Enter: Run cell, insert below

Markdown Cells

  • Ctrl + 1: Convert to heading 1
  • Ctrl + 2: Convert to heading 2
  • Ctrl + 3: Convert to heading 3
  • Ctrl + 4: Convert to heading 4
  • Ctrl + 5: Convert to heading 5
  • Ctrl + 6: Convert to heading 6
  • Ctrl + M, M: Convert to markdown
  • Ctrl + M, Y: Convert to code

Navigation

  • Ctrl + Shift + -: Split cell at cursor
  • Ctrl + Up: Move cursor to cell start
  • Ctrl + Down: Move cursor to cell end
  • Ctrl + Shift + Up: Select to cell start
  • Ctrl + Shift + Down: Select to cell end

Kernel

  • Ctrl + .: Restart kernel
  • Ctrl + Alt + .: Interrupt kernel
  • Ctrl + Shift + .: Restart kernel and clear output
@pizofreude
Copy link
Author

Run Jupyter lab or notebook in detach mode

jupyter lab &
jupyter notebook &

Using the command:

jupyter lab &

will run Jupyter Lab in the background of your current shell session. However, this has a key limitation:

  • ✅ The process runs in the background
  • ❌ It will still terminate if you close the terminal or exit the shell

This happens because the background job is tied to the lifetime of the shell session. If you close the terminal or log out, the process may receive a HUP (hangup) signal and stop running.

To Keep It Running After Closing the Terminal

To ensure Jupyter Lab continues running even after you close the terminal, you should combine & with nohup or use a session manager like tmux or screen.

✅ Recommended Alternatives

  1. Using nohup:

    nohup jupyter lab --no-browser &
    • nohup ignores the hangup signal
    • The output is saved to nohup.out unless redirected
    • The process continues even after terminal closure
  2. Using tmux (terminal multiplexer):

    tmux new -s jupyter
    jupyter lab

    Then press Ctrl+B, then D to detach. You can reattach later with:

    tmux attach -t jupyter
  3. Using screen (another terminal multiplexer):

    screen -S jupyter
    jupyter lab

    Then press Ctrl+A, then D to detach. Reattach with:

    screen -r jupyter

Summary

Method Background Survives Terminal Close Notes
jupyter lab & Simple, but not persistent
nohup jupyter lab & Good for headless servers
tmux / screen Interactive and flexible

For persistent background execution, prefer nohup, tmux, or screen over just &.

@pizofreude
Copy link
Author

pizofreude commented Jul 11, 2025

Using R with Jupter lab or notebook

The steps to use R with Jupyter Notebook are largely the same as for Jupyter Lab. Both Jupyter Notebook and Jupyter Lab rely on Jupyter kernels to support different programming languages, and for R, you use the IRkernel.

Summary:

To use R in Jupyter Notebook, follow these main steps:

  1. Install R on your system (if not already installed).
  2. Install the required R packages:
    install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
    devtools::install_github('IRkernel/IRkernel')

OR using renv package manager:

  • Initialize renv project: renv::init()
  • Install packages with renv:
     renv::install(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
  • Install IRkernel via renv: renv::install("IRkernel")
  1. Install the R kernel for Jupyter:

    IRkernel::installspec()
    # or for all users (requires admin rights):
    IRkernel::installspec(user = FALSE)

    If using renv: Snapshot dependencies -> renv::snapshot()

  2. Launch Jupyter Notebook:

    • In your terminal or command prompt, run:
      jupyter notebook
  3. In the Jupyter Notebook interface, select New > R to start a new R notebook.

Differences (minor):

Feature Jupyter Notebook Jupyter Lab
Interface Classic notebook interface More modern, modular interface
New R Notebook Location File > New Notebook > R Launcher or File > New > R Notebook
Extensions Limited Rich extension support

So, the core setup (installing IRkernel) is identical. The only difference is in how you interact with the interface once the kernel is installed.

For both environments, ensure that your jupyter command is aware of the R kernel, which the IRkernel::installspec() command handles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment