1

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
  :init
  (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?

1

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

(defun special-c-return-in-dired ()
  (interactive)
  (if (derived-mode-p 'dired-mode)
      (dired-w32explore)
    (cua-set-rectangle-mark))
  )

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

That works for me! Thanks Drew!

0

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.

  • Thank you @Drew! I wrote some lines and it works. – nephewtom Jan 13 at 13:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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