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.
Related
Im a new user in emacs, and use emacs because of the ansi-term/multi-term
Now I have to type ctrl+C twice to send it to term.
I would like to unbind the CTRL+C shortcut in emacs so I can send it directly to the term.
Is it possible?
Solution to override all other keymaps in term-mode buffers:
(defun jpk/term-mode-hook ()
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c") 'term-send-raw)
(set-transient-map map (lambda () t))))
(add-to-hook 'term-mode-hook 'jpk/term-mode-hook)
Assuming you don't have any other binds to C-c (this is unlikely, see below):
(define-key term-mode-map (kbd "C-c") 'term-send-raw)
This was sufficient for me when starting emacs with emacs -q (i.e. without any of my customizations).
It is possible to change the key binding, but in my opinion it isn't worth it. C-c is a prefix key in Emacs, meaning that many key bindings start with it. You'll be fighting pervasive conventions and you will probably be frustrated. Accept that Emacs is not 100% a terminal emulator and there are a few minor compromises to be made.
Not too sure what you're asking, but binding a key to nil unbinds it.
So for a global C-c binding: (global-set-key "\C-c" nil).
And for a local binding in mode foo: (define-key foo-mode-map "\C-c" nil).
Note that you might need to undefine it in more than one local map. Remember too that you can use (current-local-map) and (current-global-map). For example, if you use M-x report-emacs-bug then C-c is a key prefix for multiple keys, in multiple keymaps. To undefine it in the bug-reporting buffer, you will need to use both of these:
(define-key (current-local-map) "\C-c" nil)
(define-key mml-mode-map "\C-c" nil)
How did I find out that mml-mode-map was involved? C-c C-h.
In Emacs evil mode, the key combo C-z is to toggle evil mode. I would like to rebind it to escape to shell instead. How would I do this ?
I have read about eshell, it seems to be great, but for now I would like to work with my zsh shell first.
Multi term seems to designed for this job, but I think escaping to shell is fine for me, since I'm used to this flow in Vim.
Thanks for reading.
Perhaps what you need is C-x C-z.
Just have the same requirement, and here's my configurations:
(add-to-list 'load-path "~/.emacs.d/evil")
(add-to-list 'load-path "~/.emacs.d/evil/lib")
(setq evil-toggle-key ""); remove default evil-toggle-key C-z, manually setup later
(require 'evil)
(evil-mode 1)
;; remove all keybindings from insert-state keymap, use emacs-state when editing
(setcdr evil-insert-state-map nil)
;; ESC to switch back normal-state
(define-key evil-insert-state-map [escape] 'evil-normal-state)
Ref:
1. https://gist.github.com/kidd/1828878
2. https://askubuntu.com/questions/99160/how-to-remap-emacs-evil-mode-toggle-key-from-ctrl-z
C-x C-z will suspend the frame and return you to the shell.
C-z as you mention toggles evil mode on/off.
I swap their behavior in evil like so:
(define-key evil-motion-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-emacs-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-motion-state-map (kbd "C-x C-z") 'evil-emacs-state)
(define-key evil-emacs-state-map (kbd "C-x C-z") 'evil-exit-emacs-state)
See this commit for an example (where I also make C-z emulate vim-behavior in insert/replace mode).
I'm using M-<left> and M-<right> to cycle buffers in Emacs 24 (with previous-buffer and next-buffer respectively). I also use C-<tab> to cycle through frames.
In Org mode those keys are bound to specific functions. The problem is, if I position the cursor in a neutral area (over whitespace), the keys register and fail; I'd like them to fall back to the behaviour detailed above.
Sadly I don't speak Lisp so I can't tacle the problem on my own.
How can I define a shortcut to custom behaviour when over whitespace in Org mode?
If the issue only presents itself in org-mode, then my best guess is that there are key definitions in that major mode that are trumping your global key settings. One option would be to remove the org-mode-map definitions that are affecting your global settings, and reassign them to different keys. To remove org-mode-map definitions, here is one possible method:
(eval-after-load "org" '(progn
(define-key org-mode-map (kbd "<M-left>") nil)
(define-key org-mode-map (kbd "<M-right>") nil)
(define-key org-mode-map (kbd "C-<tab>") nil) ))
I'm trying to map Ctrl + minus ("C--") to undo in Emacs 24.3 (from http://emacsformacosx.com) in Mac OS X 10.8.4, but I can't get it to work. There seems to be some very global key binding for decreasing the font size, which I can't seem to override. Can anyone tell me what I'm doing wrong?
I have the following in my .emacs.
(global-set-key (kbd "C--") 'undo) ;; Doesn't work
(global-set-key (kbd "C-u") 'undo) ;; Just for testing, does work
When I press Ctrl+U, it triggers undo, but when I press Ctrl+minus, it decreases the font size. It might be simply that I should use something other than "C--", but it looks like it should work. I checked the key bindings (via C-h b) and there, C-u is bound to undo, but C-- is bound to text-scale-decrease. It would probably be possible to find where that key is bound and get some clue, but my Emacs-fu is too weak.
I'm using the graphical version of Emacs, not the terminal version.
With these type of problems I usually
try f1 k and right after the key combination that I'm having a problem with,
C-- in your case.
One of two things should happen:
Nothing happens - this means that the shortcut is being intercepted
at the level of the operating system.
It gives you a description of a function that's being called.
It's probable that it was set by either your major mode or one of the minor modes.
So you should investigate that as well, searching though the references
to this function, which is text-scale-decrease in you case.
After you find either global-set-key, or local-set-key or define-key
with this function, either comment it out, or better just
call the same function with same shortcut and nil in your ~/.emacs.
UPD: how to unset a key
When you find that some source that you're loading e.g. starter-kit is setting the key,
you just need to unset it later in the same way:
If it was set with (global-set-key (kbd "C--") 'text-scale-decrease),
you unset it with (global-set-key (kbd "C--") nil).
If it was set with (define-key markdown-mode-map (kbd "C--") 'text-scale-descrease),
you unset it with (define-key markdown-mode-map (kbd "C--") nil).
If it was set with
(add-hook 'markdown-mode-hook
(lambda()(local-set-key (kbd "C--") 'text-scale-descrease))
you unset with
(add-hook 'markdown-mode-hook
(lambda()(local-set-key (kbd "C--") nil))
I have two problems which are somewhat related I believe:
1) In IDO I'd like to change ido-restrict-to-matches to samething else than C-SPC or C-#. Unfortunately I do not know how to tell emacs that I want a different shortcut (say C-0).
2) I'd like to protect my C-; but whenever flyspell-mode is running it overtakes C-;. My definition is in .emacs as:
(global-set-key (kbd "C-;") 'mark-paragraph)
but apparently flyspell overwrites this... (although even then, if I look in the help M-h k C-; it does say mark-paragraph)
Could somebody please tell me how to bind/unbind keys in these conditions? It has to work without modifying ido.el and flyspell.el and re-building, right?
Thanks very much!
Flyspell provides a customization for the C-; binding, so you can either M-x customize RET flyspell-auto-correct-binding RET or put something like this in your ~/.emacs:
(setq flyspell-auto-correct-binding (kbd "C-~")) ; or a binding of your choice
As for ido, your question is slightly confusing, because it implies there are times when you're using ido outside the minibuffer...
The documentation in ido.el contains the following advice:
;; To modify the keybindings, use the ido-setup-hook. For example:
;;(add-hook 'ido-setup-hook 'ido-my-keys)
;;
;;(defun ido-my-keys ()
;; "Add my keybindings for ido."
;; (define-key ido-completion-map " " 'ido-next-match)
;; )
Using that knowledge, you can change the key bindings like this in your own "ido-my-keys" function:
(define-key ido-completion-map (kbd "C-SPC") nil)
(define-key ido-completion-map (kbd "C-#") nil)
(define-key ido-completion-map (kbd "C-0") 'ido-restrict-to-matches)
There's an additional ido hook specifically for the minibuffer, too, but it's not clear why you would need that: ido-minibuffer-setup-hook.