Question

I would like to use Ctrl + Tab in EMACS for my own use, but Emacs org mode already has this bound. How can I use my own binding instead of the org-mode binding.

In my .emacs file I use:

(global-set-key (kbd "<C-tab>") 'switch-view )

and it works everywhere except in org-mode

Was it helpful?

Solution

The key binding you describe is defined in org.el like this:

(org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)

This means that it is only valid in org-mode-map, one of org-mode's local keymaps. The following code adds a hook that is run when org-mode starts. It simply removes that key binding from org-mode-map.

(add-hook 'org-mode-hook
          '(lambda ()
             (define-key org-mode-map [(control tab)] nil)))

Add this code to your .emacs file and then restart emacs.

OTHER TIPS

A more robust way to set the keybindings that you want to take effect everywhere regardless of the major mode is to define a global minor mode with a custom keymap.

Minor modes can also have local keymaps; whenever a minor mode is in effect, the definitions in its keymap override both the major mode's local keymap and the global keymap

( http://www.gnu.org/software/emacs/manual/html_node/emacs/Local-Keymaps.html )

That way you don't need to mess with the major mode's local keymap every time you encounter a mode that clobbers your keybinding.

See this Q&A for details:
Globally override key binding in Emacs

This doesn't work because, as you said, org-mode uses its own keybinding for C-TAB. In other words, even if you define a global keybinding, as soon as you invoke org-mode, it will overwrite that binding with its local keybindings.

What you can do, however, is add a callback function that is invoked whenever you start org-mode, and in that callback function you reset C-TAB to invoke switch-view:

(add-hook 'org-mode-hook (lambda () (local-set-key [(control tab)] 'switch-view)))

Put the above line in your .emacs file and next time you start a new Emacs you should be good to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top