Keyboard shortcuts: Create block {before, after} current block at same indentation level

Add the following code inside file custom.js (restart Logseq and permit to run when asked):

document.addEventListener("keydown", (e)=>{    
    if (e.altKey) {
        if (e.key === "Enter") {
            const blockId = logseq.api.get_current_block().uuid
            const options = {focus: true, sibling: true, before: e.shiftKey}
            logseq.api.insert_block(blockId, "", options)
        }
    }
});
  • For consistency, I have opted for the following shortcuts:
    • ⌥⏎ to insert block below
    • ⌥⇧⏎ to insert block above
  • If you still prefer the inverse, just replace e.shiftKey with !e.shiftKey
6 Likes