Keyboard shortcut customization guide

To make it a bit easier for non-techies to modify your keyboard shortcuts, I’ve put all the currently useable keyboard shortcuts into a form that you can load into your config.edn file. You can copy the code below into directly into the file, above the :commands block, for instance.

;; These represent the default key bindings for Windows and Linux
;; (MacOS binding shown to the right, where different.)
;; MacOS: `mod` = `command`
;; Windows/Linux: `mod` = `control`
;;
;; To change key bindings, uncomment the line (delete the `;;`)
;; and put your new key bindings in quotes after the command name
;; 
;; Check [this](https://craig.is/killing/mice#api.bind)
;; for the specific bind syntaxes that mousetrap support.
;;
;; Copy and paste the :shortcuts block into your config.edn file

:shortcuts {
;;     ;; These are shortcuts when not in edit mode
;;     ;; Type the keys one after another
;;     :editor/toggle-document-mode "t d"
;;     :ui/toggle-theme "t t"
;;     :ui/toggle-right-sidebar "t r"
;;     :ui/toggle-new-block "t e"
;;     :ui/toggle-between-page-and-file "s"

;;     ;; These cannot be changed
;;     ;; "tab" (-> (editor-handler/on-tab :right)
;;     ;;         enable-when-not-editing-mode!)
;;     ;; "shift+tab" (-> (editor-handler/on-tab :left)
;;     ;;             enable-when-not-editing-mode!)

;;     :editor/undo "mod+z"
;;     :editor/redo "mod+y"
;;     ;; :editor/redo "mod+shift+z"

;;     :go/search "mod+u"
;;     :go/journals "alt+j" ;; (if util/mac? "mod+j" "alt+j")
;;     :editor/zoom-in "alt+right" ;; (if util/mac? "mod+." "alt+right")
;;     :editor/zoom-out "alt+right" ;; (if util/mac? "mod+," "alt+left")

;;     :editor/cycle-todo "mod+enter"
;;     :editor/expand-block-children "mod+down"
;;     :editor/collapse-block-children "mod+up"

;;     :editor/follow-link "mod+o"
;;     :editor/open-link-in-sidebar "mod+shift+o"

;;     :editor/bold "mod+b"
;;     :editor/italics "mod+i"
;;     :editor/highlight "mod+h"
;;     :editor/insert-link "mod+k"

;;     :editor/select-all-blocks "mod+shift+a"
;;     :editor/move-block-up "alt+shift+up" ;; (if util/mac? "mod+shift+up" "alt+shift+up")
;;     :editor/move-block-down "alt+shift+down" ;; (if util/mac? "mod+shift+down" "alt+shift+down")
;;     :editor/save "mod+s"

;;     :editor/next "down"
;;     :editor/prev "up"

;;     :search/re-index "mod+c mod+s"

;;     :graph/re-index "mod+c mod+r"

;;     :ui/toggle-brackets "mod+c mod+b"
}
4 Likes

It might also be useful in the future to have a separate keyboard-shortcuts.edn or similar, alongside the config.edn file instead of as part of it. Keyboard shortcuts are something most users are going to share verbatim across multiple repos, while config.edn is likely to have repo-specific settings.

4 Likes

thanks a lot for this, It’s a great reference point, this method I’d still say is not very user friendly for no-techies like @IcedAndCorrected said. Of course this post is super helpful for anyone who still wants to experiement with this.

I agree, this would be a lot cleaner, it’d be of course amazing to eventually have a simple GUI for non-techies.

With that said I’ll start customizing shortcuts straight away!! thanks again @IcedAndCorrected

3 Likes

Brilliant idea! Totally agree.

1 Like

This one would be great on the new “Look what I built” category. I mentioned the wrong one earlier :upside_down_face: !

1 Like

Agreed, still not a long-term solution for non-techies, but definitely easier than trying to pull the relevant details out of the clojure code themselves :smile:

I had to do it for myself anyway and figured others would benefit, so I’m glad it helped.

1 Like

thanks yeah you saved me a lot of time with it thanks!

Is there anything that can be done with this? Or is is just there for reference to know that it can’t be changed.

;;     ;; These cannot be changed
;;     ;; "tab" (-> (editor-handler/on-tab :right)
;;     ;;         enable-when-not-editing-mode!)
;;     ;; "shift+tab" (-> (editor-handler/on-tab :left)
;;     ;;             enable-when-not-editing-mode!)

I’ld love to make those to alt + l and alt+h to replicate my org-mode setup with evil mode

It’d be amazing for this to be possible eventually

1 Like

I kept those in there just for my own reference, based on how I copied and transformed the keyboards.cljs file.

Currently, the actual app code doesn’t allow these to be customized. I don’t think it would be too hard for the devs to add, but I’m not familar enough the codebase to know if there’s some reason those weren’t made to be customizable.

1 Like

got you, that makes sense! Excited to see how the customization of shortcuts evolves

@IcedAndCorrected I got a question about mapping this in mac.

I have my main computer on linux, but I also use a mac and I’m not sure how to make keybidinding work in both.

For example I’m trying to figure this out

    :editor/expand-block-children "alt+j" (if util/mac? "mod+j" "alt+j")
    :editor/collapse-block-children "alt+k" (if util/mac? "mod+k" "alt+k") 

That works with no issues on linux, but it’s not working on mac.


I don’t fully understand how to use this part if util/mac?

Would appreciate some help with this, I’ve been stuck trying to figure it out

Thanks!

Ah, that’s just some clojure code in the original I left in to show what the default mac key binds are.

As the code works currently, it checks to see whether you’ve set a key bind for given command in config.edn. If you do, it uses that. If you don’t have a key bind set, it chooses the default key binding based on whether you’re on a mac or anything else. As of now, if you set a key bind in config.edn, it will be the same on all platforms.

I’m in the same boat (I use macos and linux). Out of curiosity, does left_alt + j work on Mac if you use that key bind (without the (if util/mac part)?

I have been thinking about the best way to solve it. I don’t want to burden the dev team as they’re working on more important core features. The easiest solution would be to run the util/mac? check when the app reads the config.edn, and replaces alt with mod in any string, but that won’t be as flexible and could cause unexpected conflicts (e.g. you have mod+j and alt+j both mapped to something.)

I’m working on learning clojure and hope to be comfortable enough in it in the next week or so that I can start contributing PRs.

1 Like

Got you, yeah I don’t know any clojure so I’m a bit lost with the if util/mac and why mac doesn’t work with the linux set-up (which I assumes also works in windows)

In my case alt doesn’t seem to work for me, not even if I do left_alt + j

and yeah with the example I put, I was only doing mod+j and alt+j for testing, I only need alt+j since unmmaped that one from daily journal.

   :editor/expand-block-children "alt+j" (if util/mac? "mod+j" "alt+j")

I did it double based on this example from your code,

;;     :go/journals "alt+j" ;; (if util/mac? "mod+j" "alt+j")

I thought there might be some requierment to do "mod+j" "alt+j" for alt+j to work.

Good to hear I got a fellow Linux / mac user who struggles with mac’s stupid keys as well :sweat_smile: If you do figure out more about this please let me know in this post, I’ll keep an eye on it.

Thanks again for all the help!

how do I override enable-when-not-editing-mode!?

I added this but like the original shortcut, it doesn’t work unless I’m out of edit mode, I want it to always work

 :shortcuts {
       :ui/toggle-theme "mod+shift+d"
}

Man this is painful. Reminds of my org-mode days.

This is thankfully out of date, you can nowcustomize shortcuts from inside logseq settings

2 Likes

As @Aryan said, this post is outdated as you can now directly customize shortcuts in Logseq using a GUI. I’m archiving this post.