I just updated the emacs package elpy, and it's set the following keybindings:
<M-down> elpy-nav-move-iblock-down
<M-left> elpy-nav-move-iblock-left
<M-right> elpy-nav-move-iblock-right
<M-up> elpy-nav-move-iblock-up
I usually have these keys bound to windmove-<direction> and I think this is a real pain. Following this github issue, I tried:
(load "python")
(define-key elpy-mode-map [remap windmove-left] nil)
(define-key elpy-mode-map [remap windmove-right] nil)
(define-key elpy-mode-map [remap windmove-down] nil)
(define-key elpy-mode-map [remap windmove-up] nil)
in my .emacs, but no luck. How can I stop elpy-mode from overriding these keys?
You can reset the offending mappings to nil in one fell swoop in the following way. UPDATE. As per lunaryorn's comment, the file parameter should be "elpy" rather than "python", which is now reflected in the answer.
(eval-after-load "elpy"
'(cl-dolist (key '("M-<up>" "M-<down>" "M-<left>" "M-<right>"))
(define-key elpy-mode-map (kbd key) nil)))
If you're not keen on the dolist, you could wrap four calls to define-key in a progn within the eval-after-load.
Related
Here is my key binding.
I want to set C-h to delete-backward-char in all modes, but in octave mode, when I pressed C-h, it shows C-h (Type ? for further options)-. So I add the last 3 lines in my .emacs file, but it doesn't work. C-h still works as the help function.
(global-set-key (kbd "C-?") 'help-command)
(global-set-key (kbd "C-h") 'delete-backward-char)
(define-key octave-mode-map (kbd "C-h") nil)
(define-key octave-mode-map (kbd "C-h a") nil)
(define-key octave-mode-map (kbd "C-h d") nil)
octave.el appears to set those bindings in three different keymaps:
octave-mode-map
inferior-octave-mode-map
octave-help-mode-map
You might also refer to Globally override key binding in Emacs
Is there a way to make Emacs' auto-complete package not trigger menu completion on return key but instead on some other key-combination say C-Return? For a fast typist having it bound to return often causes non-deterministic behaviour of return. This because its behaviour now depends on how fast I type the previous characters.
See https://github.com/auto-complete/auto-complete.
This code should do exactly what you want
(define-key ac-completing-map (kbd "RET") nil)
(define-key ac-completing-map [return] nil)
(define-key ac-completing-map [(control return)] 'ac-complete)
I didn't try it on the terminal as I'm on windows at the moment.
I have this little problem, I have some key bindings like so C-. C-x or C-. C-m. After I activate the flyspell-mode, I cannot use these commands. In my .emacs file I have the next 2 lines before
(global-unset-key (kbd "C-."))
(define-key (current-global-map) (kbd "C-.") nil)
(global-set-key (kbd "C-. C-l") 'global-linum-mode)
Then, my C-. C-l works, but it does not when the flyspell-mode is activated. The command bound to C-. is flyspell-auto-correct-word. I tried to deactivate it as follows:
;; first try
(defun flyspell-auto-correct-word-disable() (define-key (current-local-map) (kbd "C-.") nil))
(add-hook 'flyspell-mode-hook 'flyspell-auto-correct-word-disable)
;; second try
(define-key (current-global-map) [remap flyspell-auto-correct-word] nil)
None of the tries work, what can I do? I tried in Emacs 23 and 24 and I have the same issue.
What about:
(eval-after-load "flyspell"
'(define-key flyspell-mode-map (kbd "C-.") nil))
Your first solution is almost correct, but you have to remember that the current local map is set up by the major mode, not minor modes. The best option you have it to directly access flyspell-mode-map and modify it (another option would be to find it in minor-mode-map-alist but I think it would be needlessly complicated).
Also, I prefer putting such mode-specific settings within eval-after-load (which means they will be evaluated once) rather than in a hook (in which case the settings are evaluated multiple times: each time one buffer activates flyspell-mode). But this is a matter of preference and either way is fine.
The Tab keybinding of yasnippet often overwrites other useful keys.
Is there a way to disable Tab binding of Yasnippet to enable other Tab usage?
These will remove yasnippet's key binding:
(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
Should work. Or you can bind tab to another command.
I'm late for the party but came upon the accepted answer in this question which... didn't work.
Experimented a bit and finally found a solution. Thought I should contribute an answer that does work:
;; It is crucial you first activate yasnippet's global mode.
(yas/global-mode 1)
;; The following is optional.
(define-key yas-minor-mode-map [backtab] 'yas-expand)
;; Strangely, just redefining one of the variations below won't work.
;; All rebinds seem to be needed.
(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "<tab>") nil)
With use-package:
(use-package yasnippet
:demand t
:bind (:map yas-minor-mode-map
("TAB" . nil)
("<tab>" . nil))
:config
(yas-global-mode))
(setq yas-minor-mode-map ;This MUST before (require 'yasnippet)
(let ((map (make-sparse-keymap)))
(define-key map (kbd "M-i") 'yas-expand)
(define-key map "\C-c&\C-n" 'yas-new-snippet)
(define-key map "\C-c&\C-v" 'yas-visit-snippet-file)
map))
(require 'yasnippet)
This is driving me nuts.
I've bound M-e to some useful stuff, but cc-mode is hogging it. I've tried adding c-mode-hooks, c-mode-commons and I've tried eval-after-load on c-mode, ie
(eval-after-load "c-mode"
'(define-key c-mode-map (kbd "M-e") nil))
but whenever I open a C file, M-e is still bound to c-end-of-statement. How do I disable it and replace it with my own bindings?
Maybe you could try this
(define-key c-mode-map [remap c-end-of-statement] 'your-useful-stuff)
or
(define-key cc-mode-map [remap c-end-of-statement] 'your-useful-stuff)