I want to set a shift combo shortcut for my custom function like this.
(global-set-key (kbd "S-u") 'my-custom-function)
But when I complete this and click "shift + u", it report "U is undefined" error.
How about just (global-set-key "U" #'my-custom-function)
Setting that binding will make it hard to type normally though, you will need to quoted insert every time you want to type a capital "U" unless you have done some modifications to your keys.
Related
I am trying to bind the multiple-cursors.el click event, using the following line in my .emacs configuration file:
(global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click)
I don't get this specific sequence of keys, here is what I am doing now :
C => Ctrl
S => Shifts
<mouse-1> => mouse click (left? right?)
But when I press CtrlShifts I am prompted with the search in the minibar.
How do I get this shortcut working ?
Note : in case this is relevant, I am using emacs-prelude.
Edit : I made it working with the following lines, but I am still curious about the meaning of the previous sequence.
(global-unset-key (kbd "M-<down-mouse-1>"))
(global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)
The "S" you mentioned is spurious.
The C-S-<mouse-1> sequence is just Ctrl+Shift+Left click.
The reason you were getting dropped into the minibuffer requesting search input is because by default Ctrl+s is bound to isearch-forward.
Edit: I may have misread what you were looking for.
If you actually want to use the sequence Ctrl+Shift+s followed by Left click then you have use the following mapping:
(global-set-key (kbd "C-S-s <down-mouse-1>") 'mc/add-cursor-on-click)
Thanks to #resueman below for pointing this out.
I’m on a Mac and would like to use the function key F19 as meta.
(There’s a good reason, although it's a bit of a hack: My built (the otherwise excellent port by Yamamoto Mitsuharu) doesn’t support using only the left alt key as meta while preserving the native behavior (inserting special characters) of the right alt key.. So I remapped the left alt key to an unused key - F19 - on the system level with PCKeyboardHack (xmodmap is sorely missed) and would like to tell Emacs to use that as meta.)
So, how do I: use a function key (F19 in my case) as meta key in Emacs?
(I’m fairly new to Emacs and, after some googling, tried out something like
(define-key global-map [f19] \M)
but that, of course, doesn’t do the trick (Symbol’s value as variable is void: M)
Well, with
(setq x-alt-keysym symbol)
you can tell emacs what key is to be understood as meta, but afaik it only accepts 'meta, 'alt, 'super and 'hyper as symbol. Maybe try it with f19.
An alternative option that will work but which will require adaption to a new way of working would be to use F19 as a prefix key (like you use C-h or F1 to invoke help commands):
(define-prefix-command 'f19-map)
(global-set-key (kbd "<f19>") 'f19-map)
(global-set-key (kbd "<f19> x") 'execute-extended-command)
(global-set-key (kbd "<f19> u") 'upcase-word)
...
Writing the configuration shouldn't be too hard. Just press C-h b to get all existing keybindings and edit the help buffer. Get rid of all lines that don't start with M-, then use rectangles to replace all occurrences of ^M- by (global-set-key (kbd ", and so on.
Yet another option would be to bind the key to Esc instead of F19, as long as that's supported by your system, and use the esc prefix instead of the f19 prefix. That way you don't have to change the emacs configuration at all.
When reading through the code at times, its a pain to keep pressing ctrl key or alt key in addition to n or p or other combination to keep moving around in the code.
I was wondering if there is a way to lock these keys for a while and then be able to just use combination keys to navigate around
NOTE : I don't want answers like use vim. I don't have time to read stupid answers please.
You could for example define a minor mode for which the keymap assigns navigation commands to just letters, without the C- or M- modifier.
For example:
(define-minor-mode my-minor-mode
"Navigate with easy key bindings"
; Make this a global mode (i.e. active in all buffers)
:global t
; "foo" will be printed in the modeline when this mode is active
:lighter " foo"
; Setup the keymap
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "n") 'next-line)
map))
Then, you can assign this mode to a key binding to easily switch it on and off:
(global-set-key (kbd "<f5>") 'my-minor-mode)
You might want to look at the documentation to better understand how define-minor-mode works:
C-hfdefine-minor-modeRET
Try M-x view-mode. That binds lots of single characters to various navigation commands. Type C-h f view-mode to see the entire list.
I want to override the bad default tabbing scheme in emacs so that it will work like most other editors (eclipse, notepad++). I want to set it so that regardless of mode, tab will insert a tab, and pressing enter will keep me at my current tab depth.
I tried this, but it does nothing:
(global-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq default-tab-width 4) ;; 8 is way too many
To make the Enter key take you to the next line and indent it automatically, you can put
(global-set-key (kbd "RET") 'newline-and-indent)
in your .emacs. [Or you can hit C-j instead of Enter.] Once you have that, you'll never need to insert tabs manually, because Emacs automatically indents a new line to extra depth after an opening brace, etc. If you do want to change the indentation, you can hit TAB until it takes you to the right indentation, then start typing from there. [And when you type a closing brace, Emacs is smart enough to take that brace one indentation level backwards.]
You should remove the (global-set-key (kbd "TAB") 'tab-to-tab-stop) for this to work.
Many major modes override the TAB binding, for example cc-mode binds TAB to 'c-indent-to-column.
The 'global-set-key that is suggested does nothing as almost every major mode has overridden the TAB.
One trick that might work for you is to copy the approach that 'pabbrev uses, and define a global minor mode that has the TAB bound. You could do that like so:
(defvar just-tab-keymap (make-sparse-keymap) "Keymap for just-tab-mode")
(define-minor-mode just-tab-mode
"Just want the TAB key to be a TAB"
:global t :lighter " TAB" :init-value 0 :keymap just-tab-keymap
(define-key just-tab-keymap (kbd "TAB") 'indent-for-tab-command))
However, this disables all TAB completion. You'll probably get best results by overriding each of the major-modes one by one (so as to avoid mussing up TAB completion).
This bugged me, too, when I first started using Emacs. I've come to love it, though. If I want to indent appropriately, I hit <tab>; if I want to insert a literal tab, I hit M-i (Meta and 'i' or <Alt>-<i> in some parlances) which is bound to tab-to-tab-stop.
I think trey jackson's answer is probably what you want, except possibly use 'self-insert-command instead of 'indent-for-tab-command. I personally prefer emacs' default behavior, but self-insert-command does what it says instead of trying to do anything fancy like make sure your code is well-formatted.
The few times I actually want to insert a tab (not indent) I press M-i.
You may be interested in this minor mode I created at http://github.com/vohrta/regtab.
It makes it so that when you press the tab key either a tab character (if indent-tabs-mod is not nil) or tab-width spaces will be placed at point. The mode is also capable of handling what you may consider regular behavior on a region of selected text and shift-tabbing to remove tabs at the beginning of the line (or set of lines).
You can enable or disable it at any time by pressing M-x regtab-mode.
C-j does the newline + indent functionality that you want out of pressing Enter.
How do you set a function to \C-' ? when I try to do :
(global-set-key "\C-'" 'myfunct)
it gives me "Invalid modifier in string".
What is \C-'? Do you want something to happen when you type backslash+c+quote? Or do you mean C-' (control+quote)? If it's the latter (and I guess it is), then you should use
(global-set-key (kbd "C-'") 'myfunct)
For any key sequence you want to use, press C-h k and then press the key sequence you want to use. Then it tells you the name of the key. That name is what should be used (with the code in the accepted answer).