Rebind emacs “C-d” to delete word

泄露秘密 提交于 2019-12-12 13:28:39

问题


I have tried several different ways of doing this, and none have been successful. I want to switch the M-d and C-d functionality (delete word, delete char) respectively while working in c++ files.

Can someone please lend me a hand?


回答1:


(add-hook 'c-initialization-hook
          (lambda ()
            (define-key c++-mode-map "\C-d" 'kill-word)
            (define-key c++-mode-map "\M-d" 'c-electric-delete-forward)))

From CC Hooks - CC Mode Manulal:

Variable: c-initialization-hook

Hook run only once per Emacs session, when CC Mode is initialized. This is a good place to change key bindings (or add new ones) in any of the CC Mode key maps. See Sample .emacs File.




回答2:


(eval-after-load "cc-mode"
  '(progn
     (define-key c++-mode-map (kbd "C-d") 'kill-word)
     (define-key c++-mode-map (kbd "M-d") 'delete-char)))


来源:https://stackoverflow.com/questions/12392915/rebind-emacs-c-d-to-delete-word

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