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", "i"], seq_mac: ["⌘", "i"], press_all: true, desc: "Show identifier documentation", basic: true }, %{ 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 Elixir cell below", basic: true}, %{seq: ["m"], desc: "Insert Markdown cell below", basic: true}, %{seq: ["N"], desc: "Insert Elixir cell above"}, %{seq: ["M"], desc: "Insert Markdown cell above"}, %{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 stale/new 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", "r"], desc: "Show runtime settings"}, %{seq: ["s", "b"], desc: "Show bin"}, %{seq: ["0", "0"], desc: "Restart current runtime"} ], universal: [ %{ seq: ["ctrl", "↵"], seq_mac: ["⌘", "↵"], press_all: true, desc: "Evaluate cell in either mode", 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.
<.shortcuts_section title="Navigation mode" shortcuts={@shortcuts.navigation_mode} basic={@basic} platform={@platform} /> <.shortcuts_section title="Insert mode" shortcuts={@shortcuts.insert_mode} basic={@basic} platform={@platform} /> <.shortcuts_section title="Universal" shortcuts={@shortcuts.universal} basic={@basic} platform={@platform} /><.shortcut shortcut={shortcut} platform={@platform} /> | <%= shortcut.desc %> |