Change keybinding

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."
    (keymaps:define-keyscheme-map "custom" (list :import %slot-value%)
      nyxt/keyscheme:emacs ; use `nxyt/keyscheme:vi-normal' for VI bindings
       "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)
  `(let ((scheme ,keyscheme))
     (keymap:define-key (gethash ,scheme-name scheme)
  `(keymaps:define-keyscheme-map "custom" (list :import ,keyscheme)
     (list ,@bindings)))

which you can use like that:

(define-configuration base-mode
  "Rebind C-l in Emacs map to copy-username command."
    (alter-keyscheme %slot-value%
      "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

Hi. I would like to extend the functionality of nyxt/password-mode (now renamed to nyxt/mode/password in rel 3) to perform not just copy to clipboard, but to paste it into the input box.

So I tried this approach:
(define-command my-copy-password (&optional (buffer (current-buffer)))
“Query password and paste”
(nyxt/mode/password:copy-password buffer)
(nyxt/mode/document:paste buffer))
(define-command my-copy-username (&optional (buffer (current-buffer)))
“Query username and paste”
(nyxt/mode/password:copy-username buffer)
(nyxt/mode/document:paste buffer))
(defvar my-keymap (make-keymap “my-map”))
(define-key my-keymap
;; “C-M-p” 'nyxt/mode/password:copy-password
;; “C-M-u” 'nyxt/mode/password:copy-username
“C-M-p” 'my-copy-password
“C-M-u” ‘my-copy-username)
(define-mode my-mode ()
"Dummy mode for the custom key bindings in `my-keymap.’"
((visible-in-status-p nil)
(keyscheme-map (keymaps:make-keyscheme-map
nyxt/keyscheme:emacs my-keymap))))

The problem here is that nyxt/mode/password:copy-username and copy-password are asynchronous functions (i.e. they return a promise is probably the correct techincal description). So the clipboard is not updated until the user has selected a keepass entry. So the nyxt/mode/document:paste function pastes whatever (i.e. stale) content it has in the input box in the web buffer.

I would appreciate the guidance on how to wait for the promise to complete before invoking the paste function.


No, wait, it doesn’t return promise, it’s actually synchronous (if you invoke it programmatically, at least). What takes time here is actually filling the clipboard. So if you add a slight delay before pasting it’s all magically working. I’ve tried half a second and one second:

  • Half a second didn’t work, was too short for the clipboard.
  • One second did miraculously work.

You machine can have a different timing, so measure it yourself, but here’s a version of my-copy-password that worked for me:

(define-command my-copy-password (&optional (buffer (current-buffer)))
  "Query password and paste it right after it."
  (nyxt/mode/password:copy-password buffer)
  (sleep 1)
  (nyxt/mode/document:paste buffer))

P.S. And sorry for the late reply, I wanted to get back to it knowing all the data and debugging everything for a while now :sweat_smile: