I installed Jedi mode in Emacs. I noticed that it overrides C-c . and C-c , (goto-definition and goto-definition-pop-marker respectively).
Here is how I set it up in my init file:
(setq jedi:setup-keys t)
(add-hook 'python-mode-hook 'jedi:setup)
I am using another mode called multiple-cursors that is set up as follows:
(add-to-list 'load-path "~/.emacs.d/multiple-cursors.el/")
(global-set-key (kbd "C-c .") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c ,") 'mc/mark-previous-like-this)
Once jedi-setup loads, it rebinds my C-c . and C-c ,. What I'd like to do is keep my multiple cursors bindings and remap Jedi's bindings. I tried adding this to the end of my Jedi setup but it ends up mapping the Jedi functions to both C-c./, and C-c j/k at the same time.
(setq jedi:key-goto-definition (kbd "C-c k"))
(setq jedi:key-goto-definition-pop-marker (kbd "C-c j"))
The reason this happens is because Jedi binds them on the regular C-c ./, mappings, then just adds another C-c j/k mapping.
How do I stop Jedi from completely not binding to the C-c ./, and only bind to C-c j/k?
Unbind the keys you want in the Jedi mode keymap: just bind them to nil in that map.
Or change the order of the entries in minor-mode-map-alist.
See (elisp) Controlling Active Maps.
Related
I switch windows with M-left and M-right. Also Tab, S-Tab and C-Tab are hardwired into my spine. Since I use markdown-mode my workspeed has halved.
How do I disable that markdown-mode re-assigns those keys on loading. The keys I describe are carefully handcrafted shortcuts from my .emacs file, set via global-set-key.
(global-set-key [S-iso-lefttab] 'dabbrev-expand)
(global-set-key [C-tab] 'ispell-word)
(global-set-key [M-up] 'windmove-up)
(global-set-key [M-down] 'windmove-down)
(global-set-key [M-left] 'windmove-left)
(global-set-key [M-right] 'windmove-right)
Set those keys also in markdown-mode, in its keymap (probably markdown-mode-map). For example:
(define-key markdown-mode-map [C-tab] 'ispell-word)
The problem you saw comes from the fact that a local binding overrides a global one. See the Elisp manual, node Active Keymaps.
I've used keybindings that start with "C-," in many other major modes and they all work. But it does not seem to work in org-mode (I tried to bind "C-, C-d" to org-deadline).
This is how I bind keys:
(add-hook 'org-mode-hook
(lambda ()
(local-set-key (kbd "C-, C-d") 'org-deadline)))
It looks like if I change it to
(add-hook 'org-mode-hook
(lambda ()
(local-set-key "\C-cp" 'org-deadline)))
then the binding works. However, it is still unclear to me how to bind "C-, C-d". And the first way of binding works in other major modes (Latex, Python, etc...) I use.
local-set-key in this context will attempt to bind a key sequence in org-mode-map, and there is already a non-prefix binding for C-, in that keymap, so you can't then create a binding in the same keymap which treats C-, as a prefix.
n.b. You can ask Emacs what C-, is bound to by typing C-h k C-, in an org-mode buffer.
You can remove the default binding using:
(eval-after-load "org" '(define-key org-mode-map (kbd "C-,") nil))
(after which you would be able to execute your original code.)
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 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.
I want to map C-f C-b as moving forward and backward by a fixed amount of lines in a file.
I did this:
(global-set-key (kbd "C-f") 'next-line)
(global-set-key (kbd "C-b") 'previous-line)
but I don't know how to specify an argument before the next-line command. I guess I should use digit-argument but I am unable to write the command in a correct way.
You've changed your question to be about how to bind directly to key sequences
This binds C-c l to C-u 5 C-n
(global-set-key (kbd "C-c l") (kbd "C-u 5 C-n"))
One of the possible alternatives would be define a new function:
(defun my-next-line ()
(interactive)
(next-line 5))
(global-set-key (kbd "C-f") 'my-next-line)
Otherwise, if it is just something you can accomplish with the keyboard you might want to use
M-x name-last-kbd-macro
and save it in your .emacs file
M-x insert-kbd-macro
and have emacs implement the function for you.
It will just get the name you gave in your call to name-last-kbd-macro