defmodule LivebookWeb.SessionLive.ShortcutsComponent do use LivebookWeb, :live_component @shortcuts %{ insert_mode: [ %{seq: ["esc"], desc: "Switch back to navigation mode", basic: true}, %{seq: ["tab"], desc: "Autocomplete expression when applicable", basic: true}, %{ seq: ["ctrl", "␣"], press_all: true, desc: "Show completion list, use twice for details", basic: true }, %{ seq: ["ctrl", "shift", "␣"], seq_mac: ["⌘", "⇧", "␣"], press_all: true, desc: "Show signature help" }, %{ seq: ["ctrl", "shift", "i"], seq_mac: ["⇧", "⌥", "f"], seq_windows: ["shift", "alt", "f"], press_all: true, desc: "Format Elixir code", basic: true }, %{ seq: ["ctrl", "/"], seq_mac: ["⌘", "/"], press_all: true, desc: "Toggle lines comment" }, %{ seq: ["ctrl", "shift", "k"], seq_mac: ["⌘", "⇧", "k"], press_all: true, desc: "Delete lines" }, %{ seq: ["ctrl", "]"], seq_mac: ["⌘", "]"], press_all: true, desc: "Indent lines" }, %{ seq: ["ctrl", "["], seq_mac: ["⌘", "["], press_all: true, desc: "Outdent lines" }, %{ seq: ["ctrl", "h"], seq_mac: ["⌘", "⌥", "f"], press_all: true, desc: "Replace" }, %{ seq: ["alt", "↑"], seq_mac: ["⌥", "↑"], press_all: true, desc: "Move lines up" }, %{ seq: ["alt", "↓"], seq_mac: ["⌥", "↓"], press_all: true, desc: "Move lines down" }, %{ seq: ["ctrl", "←"], seq_mac: ["⌥", "←"], press_all: true, desc: "Cursor skip word left" }, %{ seq: ["ctrl", "→"], seq_mac: ["⌥", "→"], press_all: true, desc: "Cursor skip word right" } ], navigation_mode: [ %{seq: ["?"], desc: "Open this help modal", basic: true}, %{seq: ["j"], desc: "Focus next cell", basic: true}, %{seq: ["k"], desc: "Focus previous cell", basic: true}, %{seq: ["J"], desc: "Move cell down"}, %{seq: ["K"], desc: "Move cell up"}, %{seq: ["i"], desc: "Switch to insert mode", basic: true}, %{seq: ["n"], desc: "Insert Code cell below", basic: true}, %{seq: ["m"], desc: "Insert Markdown cell below", basic: true}, %{seq: ["N"], desc: "Insert Code cell above"}, %{seq: ["M"], desc: "Insert Markdown cell above"}, %{seq: ["z"], desc: "Toggle code zen"}, %{seq: ["d", "d"], desc: "Delete cell", basic: true}, %{seq: ["e", "e"], desc: "Evaluate cell"}, %{seq: ["e", "s"], desc: "Evaluate section"}, %{seq: ["e", "a"], desc: "Evaluate all outdated cells", basic: true}, %{seq: ["e", "x"], desc: "Cancel cell evaluation"}, %{seq: ["s", "s"], desc: "Toggle sections panel"}, %{seq: ["s", "u"], desc: "Toggle users panel"}, %{seq: ["s", "e"], desc: "Toggle secrets panel"}, %{seq: ["s", "r"], desc: "Show runtime panel"}, %{seq: ["s", "b"], desc: "Show bin"}, %{seq: ["s", "p"], desc: "Show package search"}, %{seq: ["0", "0"], desc: "Reconnect current runtime"} ], universal: [ %{ seq: ["ctrl", "↵"], seq_mac: ["⌘", "↵"], press_all: true, desc: "Evaluate cell in either mode", basic: true }, %{ seq: ["shift", "↵"], seq_mac: ["⇧", "↵"], press_all: true, desc: "Evaluate cell and advance to next one", basic: true }, %{ seq: ["ctrl", "shift", "↵"], seq_mac: ["⌘", "⇧", "↵"], press_all: true, desc: "Evaluate current and all outdated cells", basic: true }, %{ seq: ["ctrl", "s"], seq_mac: ["⌘", "s"], press_all: true, desc: "Save notebook", basic: true } ] } @impl true def mount(socket) do {:ok, assign(socket, shortcuts: @shortcuts, basic: false)} end @impl true def render(assigns) do ~H"""
Livebook highly embraces keyboard navigation to improve your productivity. It operates in one of two modes similarly to the Vim text editor. In navigation mode you move around the notebook and execute commands, whereas in the insert mode you have editor focus and directly modify the given cell content.
<.shortcut shortcut={shortcut} platform={@platform} /> | <%= shortcut.desc %> |