This question already has answers here:
Unset 'Tab' binding for yasnippet?
(4 answers)
Closed 8 years ago.
How to unset yasnippet's tab key default behaviour or even redefine it?
I am having issues getting yasnippet and auto-complete to play well together and, in particular, find the Tab key behaviour to be problematic at times as auto-complete tends to prevent yasnippet from expanding snippets.
Experimented a bit and finally found a solution that works.
;; It is crucial you first activate yasnippet's global mode.
(yas/global-mode 1)
;; This illustrates how to redefine yas-expand to S-TAB.
(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)
Related
This question already has an answer here:
How to get completion for yasnippets using auto-complete
(1 answer)
Closed 7 years ago.
I have configured yasnippet and auto-complete bindings so it won't collide, auto complete uses <tab> and yasnippet uses <backtab>:
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
;; Remove Yasnippet's default tab key binding
(define-key yas-minor-mode-map (kbd "<tab>") nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
;; Set Yasnippet's key binding to shift+tab
(define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
I created two yasnippets one with the key lorem_dummy and the other with the key lorem_image, one of the examples:
# -*- mode: snippet; require-final-newline: nil -*-
# name: lorem_image
# key: lorem_image
# binding: direct-keybinding
# --
<img src="http://lorempixel.com/${1:width}/${2:height}/${3:$$(yas-choose-value '("abstract" "city" "animals" "food" "people" "transport" "business" "sports" "technics"))}/${4:text}" alt="$3">
is it possible to make Emacs auto complete work if I just write lorem and press to show in a dropdown the two choices ( lorem_dummy and lorem_image )? Because right now it doesn't come up the yasnippets, but the regular autocomplete does work ( variables and the rest of the stuff ).
-- update --
Ok, this is strange, after following the solution in the "duplicated question" link, everything seemed to work perfectly, but then after a few hours it started to behave strange, randomdly, sometimes it works sometimes it doesn't. I made a video showing the problem, it works, then I restart Emacs and stops working again.
video
Add ac-source-yasnippet to your ac-sources, e.g.
(eval-after-load "auto-complete"
'(add-to-list 'ac-sources 'ac-source-yasnippet))
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) ))
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Globally override key binding in Emacs
In my .emacs file, I added a keybinding for control-meta-h
(global-set-key (kbd "C-M-h") 'windmove-left)
It works fine, as long I don't enter c-mode or c++-mode. Both overwrite it by the default behavior, which is c-mark-function. How you I avoid that my binding is overwritten by the c-mode/c++-mode hook?
Can be solved by defining the keybinds in a separate minor mode. For details, see Globally override key binding in Emacs, where scottfrazer provides the following solution:
(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
(define-key my-keys-minor-mode-map (kbd "C-M-h") 'windmove-left)
(define-minor-mode my-keys-minor-mode
"A minor mode so that my key settings override annoying major modes."
t " my-keys" 'my-keys-minor-mode-map)
(my-keys-minor-mode 1)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Override Ctrl-TAB in EMACS org.mode
I'm trying to rebind C-y to redo.
I've tried all possible options:
(global-unset-key (kbd "C-y")), outside and inside a org mode hook,
and (define-key org-mode-map (kbd "C-y") nil).
Yet nothing. Outside of OrgMode it acts perfectly fine, but inside? it yanks.
This is actually not to first KeyBinding that doesn't work whenever I'm inside OrgMode,
and it boggles me.
Help, please.
After quick help from the fabulous phils, I stumbled upon two things:
Globally override key binding in Emacs
which I currently use, and
http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/
which I will surely read ASAP.
Thanks Phils;)
My current setup is this:
(defvar custom-keys-mode-map (make-keymap) "custom-keys-mode keymap.")
(define-minor-mode custom-keys-mode
"A minor mode so that my key settings override annoying major modes."
t " my-keys" 'custom-keys-mode-map)
(custom-keys-mode 1)
(defun my-minibuffer-setup-hook ()
(custom-keys-mode 0))
(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
(defadvice load (after give-my-keybindings-priority)
"Try to ensure that my keybindings always have priority."
(if (not (eq (car (car minor-mode-map-alist)) 'custom-keys-mode))
(let ((mykeys (assq 'custom-keys-mode minor-mode-map-alist)))
(assq-delete-all 'custom-keys-mode minor-mode-map-alist)
(add-to-list 'minor-mode-map-alist mykeys))))
(ad-activate 'load)
(define-key custom-keys-mode-map (kbd "<C-key>") 'some-command)
This question already has answers here:
Globally override key binding in Emacs
(8 answers)
Closed 8 years ago.
I've configured my emacs to use M-j as backward-char by
(global-set-key (kbd "M-j") 'backward-char) ; was indent-new-comment-line
in my .emacs file. This works fine in many modes (text/org/lisp).
But in c++-mode & php-mode it is bound to the default c-indent-new-comment-line
How can I bind M-j to use backward-char in these modes too.
And in general for ALL modes.
Thanks,
AnotherEmacsLearner
There are policies about which keys are supposed to be mode-dependent and which not. You can overrule bindings changed by a specific mode, but it is a hassle and has to be done for every mode you will be using. It is smarter to keep your own cross-cutting neato bindings to keys that major modes will not touch out of principle. I particularly like the F1-F12 keys for that, or the Sun Function keys when I can get them. The C-c + letter sequences are also explicitly reserved for user-defined commands and will not be rebound by major modes. (See: Key Binding Conventions)
I unset keys that are in the way for specific modes like this:
(add-hook 'gnus-summary-mode-hook
(function (lambda ()
(local-unset-key '[M-down])
(local-unset-key '[M-up]))))
(add-hook 'org-mode-hook
(function (lambda ()
(local-unset-key '[S-down])
(local-unset-key '[S-left])
(local-unset-key '[S-right])
(local-unset-key '[S-up]))))
This issue was addressed in this question. The way to do this is to create a minor mode with your bindings. Your minor mode bindings will shadow any major mode's bindings.
I like your example, since just within the last couple of weeks, I rebound M-h,j,k,l to their equivalent vim movements, and made a minor mode to do it (It turned out to be a great idea. Emacs's default bindings really are terrible). Here's a sample of some of my code:
(defvar kirkland-minor-mode-map (make-keymap) "kirkland-minor-mode keymap.")
(define-key kirkland-minor-mode-map (kbd "M-h") 'backward-char)
(define-key kirkland-minor-mode-map (kbd "M-l") 'forward-char)
(define-key kirkland-minor-mode-map (kbd "M-j") 'next-line)
(define-key kirkland-minor-mode-map (kbd "M-k") 'previous-line)
(define-minor-mode kirkland-minor-mode
"A minor mode so that my key settings aren't shadowed by other major/minor modes"
t " kirkland" 'kirkland-minor-mode-map)
One other thing I should mention is that while this will override any major mode bindings, it can still be overridden by other minor modes which are loaded later.
Nothing can stop any mode from redefining any key any way it wants and it always shadows the global-set-key. So you have to redefine it for every mode that redefines it:
(defun redefine-cc-mode-keys ()
(define-key c-mode-base-map "M-J" 'backward-char))
(add-hook 'c-initialization-hook 'redefine-cc-mode-keys)
or similar.