Question

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?

Was it helpful?

Solution

(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.

OTHER TIPS

(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)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top