1

I can execute the function neotree-toggle with M-x.

However, none of these result in opening neotree, like described here and here

(global-set-key (kbd "C-e" ) 'neotree-toggle)
(global-set-key "C-e" 'neotree-toggle)
(global-set-key (kbd "\C-e" ) 'neotree-toggle)
(global-set-key "\C-e" 'neotree-toggle)

Where is my mistake? I don't see it.

  • 1
    Where are you putting those lines? The first one and the fourth one look correct. If either one is in your .emacs it should work. Try C-h C-e - this will tell you what Emacs thinks is bound to C-e. If it reports neotree-toggle, then maybe neotree isn't properly loaded. If it reports something else, your bindings didn't work. – Tyler Apr 11 '16 at 19:23
  • Perhaps try a keybinding that's not already used? I'm not familiar with overwriting a standard keybinding, but that would at least verify your syntax (which looks good to me). – Tim S. Apr 11 '16 at 19:23
  • @TimS. Emacs allows you to overwrite any keybinding, nothing is off-limits – Tyler Apr 11 '16 at 20:33
  • 2
    Sounds like you are binding a key globally but the current mode has its own keymap, and there those keys have different bindings. Or if not the current (major) mode then some minor mode. Emacs has lots of keymaps. Binding a key in the global map (which is what global-set-key does) does not mean that it takes effect everywhere. It just means that it takes effect everywhere that there is not some other keymap that binds the same key otherwise. – Drew Apr 11 '16 at 22:40
  • 1
    @toogley Tyler meant C-h k C-e – YoungFrog Apr 12 '16 at 14:06
0

I had some problems with gtags mode map at some point. I wanted to override the keybinding and use the helm-gtags key instead.

(define-key ggtags-mode-map (kbd "M-.") 'helm-gtags-dwim)

Since what you've tried to do isn't working with a global setting, it may be shadowed by a local setting or a local map. If you find that it's just a local binding, you can use local-set-key in a mode hook to override it. If it's in a mode specific map, you can use the code above as a template for your rebinding.

Update: changed the answer based on the culprit more likely being a local binding shadowing the new global setting.

  • 1
    That's not correct. global-set-key defines or redefines a key in the global map. The only fighting that might be involved is if you set a key in the global map, and that key is used in another map. Global bindings are shadowed by all other maps, but you can definitely change them. – Tyler Apr 11 '16 at 20:22
  • 1
    In that case, it may actually be that there's a local keybinding shadowing the global keybinding that is being set. – RealityMonster Apr 11 '16 at 20:30
  • Yes, which is why I suggested OP use C-h C-e to see what command is actually being called. – Tyler Apr 11 '16 at 20:32
  • That's pretty much what I was thinking, although not as well defined... good clarification. – Tim S. Apr 11 '16 at 22:53
0

I honestly don't know why, but

(global-set-key "\M-e" 'neotree-toggle)

works, but

(global-set-key "\C-e" 'neotree-toggle)

not, when executed inside my init.el. This effect is clearly reproducible, even when global-set-key is manually executed. @Tyler suggested to use C-h C-e which said for the second method at some time, its not defined. Unfortunately, i can't reproduce that and C-h C-e just shows nothing.

Thanks anyways.

  • 1
    As @YoungFrog pointed out, I meant to say C-h k C-e. – Tyler Apr 12 '16 at 16:35

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.