Unset 'Tab' binding for yasnippet?

橙三吉。 提交于 2019-12-01 16:33:26

问题


The Tab keybinding of yasnippet often overwrites other useful keys.

Is there a way to disable Tab binding of Yasnippet to enable other Tab usage?


回答1:


These will remove yasnippet's key binding:

(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)

Should work. Or you can bind tab to another command.




回答2:


I'm late for the party but came upon the accepted answer in this question which... didn't work.

Experimented a bit and finally found a solution. Thought I should contribute an answer that does work:

;; It is crucial you first activate yasnippet's global mode.
(yas/global-mode 1)

;; The following is optional.
(define-key yas-minor-mode-map [backtab]     'yas-expand)

;; Strangely, just redefining one of the variations below won't work.
;; All rebinds seem to be needed.
(define-key yas-minor-mode-map [(tab)]        nil)
(define-key yas-minor-mode-map (kbd "TAB")    nil)
(define-key yas-minor-mode-map (kbd "<tab>")  nil)



回答3:


With use-package:

(use-package yasnippet
  :demand t
  :bind (:map yas-minor-mode-map
         ("TAB" . nil)
         ("<tab>" . nil))
  :config
  (yas-global-mode))



回答4:


(setq yas-minor-mode-map ;This MUST before (require 'yasnippet)
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "M-i") 'yas-expand)
    (define-key map "\C-c&\C-n" 'yas-new-snippet)
    (define-key map "\C-c&\C-v" 'yas-visit-snippet-file)
    map)) 

(require 'yasnippet)


来源:https://stackoverflow.com/questions/14066526/unset-tab-binding-for-yasnippet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!