Editor Keyboard Shortcuts

Is there a comprehensive list of all the keyboard shortcuts? I have visited Shortcuts. It does link to the commands that have default binding. There are other shortcuts that are specific to the browser or O/S. What the editor keyboard shortcuts?

I am an Obsidian convert. I like being able to move a task/bullet up or down using Alt Up or Alt Down. I tried it and it worked. Awesome. Is there any list of these settings?

A list is here, but it only shows the ones available in read-only mode (which is what this instance is running on), that’s why a lot is missing: Keyboard Shortcuts

If you visit that page from your space via federation, you’ll get your actual keyboard bindings including any changes you made locally (and any new ones based on plugs, space scripts) you have installed. You can do this by navigating to the page !silverbullet.md/Keyboard Shortcuts on your own SilverBullet instance, either by just entering this URI in your page navigator, or by creating a link to it and clicking it: [[!silverbullet.md/Keyboard Shortcuts]].

In addition, any command with a shortcut will have it listed in the command palette as well.

1 Like

That’s great…learned a few new ones.

Can’t figure out what “Task: Postpone” does, though.

Task: Postpone got me as well. You have to be on a deadline date on a task for it to do anything.

I have redefined the shortcuts for the page picker and command pallete in settings, yet that page still shows the default ones.

also, how can i define different shortcuts for Mac and Win? E.g. if i want Ctrl+P and Cmd+P on windows perform the same function? also can i have multiple shortcuts for the same feature?

You can use key for Linux/Mac and mac for Mac specific overrides.

You cannot define multiple keyboard shortcuts to one command.

1 Like

Does this overview also exist for v2 ?

I have a temp query

${query[[from index.tag "space-lua" 
         where string.match(_.script, "key = \"([^\n]+)\",") 
         select {ref=_.ref, key=string.match(_.script, "key = \"([^\n]+)\",")}
]]}

in my SB instance/CONFIG:

and some manually maintained tables @ my SB space/CONFIG/KeyBinding

1 Like

there must be a better/easier way…

1 Like

Here is a Help-Funktion to show all the registerd shortcuts using Ctrl-Shift-?:

function toggleKeyboardShortcutsPanel()
  local isOpen = js.window.localStorage.getItem('shortcutsPanelOpen') == 'true'
  
  if isOpen then
    editor.hidePanel("rhs")
    js.window.localStorage.setItem('shortcutsPanelOpen', 'false')
  else
    local commands = system.listCommands()
    local shortcuts = {}
    
    for commandName, cmd in pairs(commands) do
      if cmd.key or cmd.mac then
        local keyDisplay = cmd.key or cmd.mac
        if cmd.mac and cmd.key and cmd.mac ~= cmd.key then
          keyDisplay = cmd.key .. " / " .. cmd.mac
        end
        
        table.insert(shortcuts, {
          key = keyDisplay,
          name = cmd.name or commandName
        })
      end
    end
    
    table.sort(shortcuts, function(a, b) return a.name < b.name end)
    
    local rows = {}
    for _, shortcut in ipairs(shortcuts) do
      table.insert(rows, string.format(
        '<tr><td class="key">%s</td><td class="cmd">%s</td></tr>',
        shortcut.key, shortcut.name
      ))
    end
    
    local html = string.format([[
      <style>
        #sb-main .panel {
          width: 12%% !important;
          max-width: 12%% !important;
          min-width: 250px !important;
          padding: 0.4em 0.3em !important;
        }
        .shortcuts-table {
          font-size: 0.95em;
          line-height: 1.35;
          width: 100%%;
        }
        .shortcuts-table th, .shortcuts-table td {
          padding: 0.25em 0.4em;
          border: none;
        }
        .shortcuts-table thead th {
          font-weight: 600;
          padding: 0.3em 0.4em;
          background-color: var(--editor-widget-background, rgba(0, 0, 0, 0.1));
          cursor: pointer;
          user-select: none;
        }
        .shortcuts-table thead th:hover {
          background-color: var(--editor-selection-background, rgba(0, 0, 0, 0.15));
        }
        .shortcuts-table thead th::after {
          content: ' ↕';
          opacity: 0.5;
          font-size: 0.8em;
        }
        .shortcuts-table thead th.sort-asc::after {
          content: ' ↑';
          opacity: 1;
        }
        .shortcuts-table thead th.sort-desc::after {
          content: ' ↓';
          opacity: 1;
        }
        .shortcuts-table tbody tr:nth-child(even) {
          background-color: var(--editor-widget-background, rgba(0, 0, 0, 0.05));
        }
        .shortcuts-table tbody tr:hover {
          background-color: var(--editor-selection-background, rgba(0, 0, 0, 0.1));
        }
        .shortcuts-table td.key {
          font-family: monospace;
          font-weight: 600;
          white-space: nowrap;
          width: 45%%;
          max-width: 180px;
          font-size: 1.15em;
        }
        .shortcuts-table td.cmd {
          width: 55%%;
        }
        .shortcuts-table tbody tr {
          height: 1.5em;
        }
        .shortcuts-header {
          position: relative;
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-bottom: 0.4em;
        }
        .shortcuts-close {
          position: absolute;
          top: 0;
          right: 0;
          cursor: pointer;
          font-size: 1.5em;
          padding: 0.2em 0.4em;
          color: var(--editor-foreground, #ccc);
          background: transparent;
          border: none;
          opacity: 0.7;
          transition: opacity 0.2s;
        }
        .shortcuts-close:hover {
          opacity: 1;
        }
        .shortcuts-header h2 {
          margin: 0;
          font-size: 1.2em;
          font-weight: 600;
        }
      </style>
      <div class="shortcuts-header">
        <h2>Keyboard Shortcuts</h2>
        <button class="shortcuts-close" title="Close">Ă—</button>
      </div>
      <table class="shortcuts-table">
        <thead>
          <tr><th>Shortcut</th><th>Command</th></tr>
        </thead>
        <tbody>%s</tbody>
      </table>
    ]], table.concat(rows, "\n        "))
    
    local script = [[
      (function() {
        const table = document.querySelector('.shortcuts-table');
        const tbody = table.querySelector('tbody');
        const headers = table.querySelectorAll('thead th');
        let currentSort = { column: -1, direction: 'asc' };
        
        function sortTable(columnIndex, direction) {
          const rows = Array.from(tbody.querySelectorAll('tr'));
          rows.sort((a, b) => {
            const aText = a.cells[columnIndex].textContent.trim();
            const bText = b.cells[columnIndex].textContent.trim();
            return direction === 'asc' ? aText.localeCompare(bText) : bText.localeCompare(aText);
          });
          rows.forEach(row => tbody.removeChild(row));
          rows.forEach(row => tbody.appendChild(row));
          headers.forEach((header, index) => {
            header.classList.remove('sort-asc', 'sort-desc');
            if (index === columnIndex) header.classList.add('sort-' + direction);
          });
          currentSort = { column: columnIndex, direction: direction };
        }
        
        headers.forEach((header, index) => {
          header.addEventListener('click', () => {
            const direction = (currentSort.column === index && currentSort.direction === 'asc') ? 'desc' : 'asc';
            sortTable(index, direction);
          });
        });
        
        document.querySelector('.shortcuts-close')?.addEventListener('click', () => {
          syscall('editor.hidePanel', 'rhs');
          localStorage.setItem('shortcutsPanelOpen', 'false');
        });
      })();
    ]]
    
    editor.showPanel("rhs", 1, html, script)
    js.window.localStorage.setItem('shortcutsPanelOpen', 'true')
  end
end

command.define {
  name = "Toggle Keyboard Shortcuts",
  key = "Ctrl-Shift-?",
  mac = "Cmd-Shift-?",
  run = toggleKeyboardShortcutsPanel
}

the table can be ordered by clicking the corresponding header…
I don’t have the knowledge yet to offer it as a “real” Silverbullet-Library and the styling could be improved for sure! :laughing:

4 Likes

One-user feedback:

  1. must say, remarkably effective!
  2. I suspect that every user, at any time, might need to call upon this plug — were its usage statistics recorded…
  3. combined with the browser’s builtin Ctrl + F, it allows one to swiftly locate the corresponding shortcut key.

Two user-feedbacks:

  1. Ctrl + Shift + / along with other shortcuts to the lowercase version of a letter seems preferable, even for special characters. On my Windows setup, two separate instances show that Ctrl + Shift + ? does not work.

  2. Could we perhaps implement a “jump to source” feature — similar to LaTeX’s terminology — where clicking a row in the table would take the user directly to its source code section? This would greatly help plugin developers quickly locate their plugin’s code, such as the relevant space-lua block.

  • For .md files this might be feasible; for .plug.js files it could be trickier, though their limited number makes it a minor concern.

I once assumed that “jump to source” could not be automated, so I built a rather rudimentary workflow and deliberately left a manual fallback: a hand-maintained table with manually added wiki links.

If this functionality could now be achieved automatically, that table might finally retire -_-||.

Good plug, anyway!

@ChenZhu-Xie Thank you for the feedback!

I have a german keyboard layout so in your case it might be CTRL-? (without the SCHIFT) but I’m not sure…

I will check how this could be implemented, at least for the .md files.
However, my programming skills are rather limited but I’m getting better at using AI :laughing:

2 Likes

I tried

[[!silverbullet.md/Keyboard Shortcuts]]

but this just gives me an empty page. What am I doing wrong?

You’re using SilverBullet v2 which doesn’t support this syntax anymore. So you’re not doing anything wrong, it’s just dated information. Have a look at some of the more recent post in this thread to see how things can be done differently in more “modern” ways.

Thank You Zef. I read all the later stuff, but it seems that was more for putting the shortcuts into a format that the user wanted. I missed that that was how they are now done.

Thank you for silverbullet. I’m loving it so far.