TAB
has multiple key bindings in different conditions. I want to change the key binding for yas-expand
from TAB
to M-TAB
. How can I do it? Basically I want TAB to run indent-for-tab-command
in all conditions.
TAB runs the command indent-for-tab-command (found in global-map), which is an
interactive compiled Lisp function in ‘indent.el’.
TAB runs the command yas-expand (found in yas-minor-mode-map), which is an
alias
for ‘yas-expand-from-trigger-key’ in ‘yasnippet.el’.
It is bound to TAB, <tab>, <menu-bar> <YASnippet> <Expand trigger>.
my setup:
(defvar my-keys-minor-mode-map
(let ((map (make-sparse-keymap)))
(global-set-key (kbd "<tab>") 'indent-for-tab-command)
yasnippet.el
library loads, you can try removing those definitions with something like this:(define-key yas-minor-mode-map [(tab)] nil)
and(define-key yas-minor-mode-map (kbd "TAB") nil)
Then define a new keyboard assignment binding the variableyas-maybe-expand
to your proposed M-TAB using theyas-minor-mode-map
. I do not have an opportunity at the moment, however, to test that out ...yas-keymap
which is used while the snippet is expanding ... see the source code as of 06/17/2021 (line 423): github.com/joaotavora/yasnippet/blob/master/yasnippet.el#L423 There are a few ways to do that ....(define-key yas-minor-mode-map [(tab)] nil); (define-key yas-minor-mode-map (kbd "TAB") nil); (define-key yas-minor-mode-map (kbd "M-TAB") 'yas-expand)
and seems like it works but I have not done anything related to your second comments. Please have look when you have time