Goal: unbind <C-return> key ONLY in dired mode in order to rebind it to dired-w32explore.
My configuration is using use-package with something like this:

(use-package dired
  (unbind-key "<C-return>" cua-global-keymap)
  :bind (:map dired-mode-map
              ("<C-return>" . dired-w32explore))

The key works in dired-mode as I want.
But I get the CUA key completely removed in the rest of modes.
Is it possible to unbind that key only for dired-mode?


Ok, so following Drew's answer, I came across with these lines:

(defun special-c-return-in-dired ()
  (if (derived-mode-p 'dired-mode)

(define-key cua-global-keymap [C-return] 'special-c-return-in-dired)

That works for me! Thanks Drew!

| improve this answer | |

cua-mode is a minor mode, so its keymap takes precedence over major-mode keymaps.

You can explicitly turn off cua-mode in dired-mode-hook, but you would then need to explicitly turn it on in other major modes where you want it on.

Alternatively, you can bind <C-return> in cua-global-keymap to your own command that checks (derived-mode-p 'dired-mode) and in that case invokes dired-w32explore and otherwise invokes cua-set-rectangle-mark.

| improve this answer | |
  • Thank you @Drew! I wrote some lines and it works. – nephewtom Jan 13 '19 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.