Change keybiding

Hello I apologize for the noob question, I did search and some info is old so not sure if is still valid for nyxt 3.x
for example, this: How to unbind a key? · Issue #1743 · atlas-engineer/nyxt · GitHub
that resolves to nil but what I need in a one-time example to change for example C-p that now is to print, to copy-password that is unbound also C-l to copy-login
thanks in advance.

So first you’d have to find where those are bound. You can use the describe-bindings command for that. It opens the page with listing for all the bindings available in the buffer you called it from. In my case (Emacs bindings), I can see that C-l is bound in base-mode-emacs-map, which means that it’s in base-mode Emacs keymap. To rebind just this symbol, you can do

(define-configuration base-mode
  "Rebind C-l in Emacs map to copy-username command."
  ((keyscheme-map
    (keymaps:define-keyscheme-map "custom" (list :import %slot-value%)
      nyxt/keyscheme:emacs ; use `nxyt/keyscheme:vi-normal' for VI bindings
      (list
       "C-l" 'nyxt/password-mode:copy-username)))))

Alternatively, you can bind it to nil (effectively un-binding it) and then bind it to some command you want in any other mode keymap.

The same procedure would work with C-p and print—search for the binding in describe-bindings, and then configure the respective mode keyscheme-map.

I acknowledge that the configuration is quite lengthy for a simple use-case like that, so you may’ve seen this macro in my config:

(defmacro alter-keyscheme (keyscheme scheme-name &body bindings)
  #+nyxt-2
  `(let ((scheme ,keyscheme))
     (keymap:define-key (gethash ,scheme-name scheme)
       ,@bindings)
     scheme)
  #+nyxt-3
  `(keymaps:define-keyscheme-map "custom" (list :import ,keyscheme)
     ,scheme-name
     (list ,@bindings)))

which you can use like that:

(define-configuration base-mode
  "Rebind C-l in Emacs map to copy-username command."
  ((keyscheme-map
    (alter-keyscheme %slot-value%
        nyxt/keyscheme:emacs
      "C-l" 'nyxt/password-mode:copy-username))))
1 Like

Also see nyxt:manual#keybinding-configuration :slight_smile:

1 Like

Thank you so much! this is perfect, now I have a clear understanding, I am using your macro and I have bind C-L and C-P