Is there anyway that we can bind C-, and C-. in emacs ? I have tried this (define-key global-map (kbd "C-,") 'action) but it doesn't seem to work.
I use Emacs on Ubuntu with US keyboard layout.
Thanks
I'm pretty your define-key does work.
But most likely when you hit C-, Emacs doesn't actually receive this.
What does C-h k C-, tell you? What about C-, C-h l ?
My crystal ball tells me you're running in a text-terminal of some sort. In those beasts many key combos don't actually get through correctly to the running application.
You could try some key binding commands, e.g.
(global-set-key [(control ?,)] 'some-action)
in your ~/.emacs file (to make your key binding permanent, and available after restart). BTW, you could evaluate that first to test it. Then restart your emacs and use C-h k C-, to check if it is bound.
Related
Using PuTTY to connect to Linux from Windows and running Emacs: How do I bind CTRL- and CTRL- to beginning-of-buffer and end-of-buffer respectively?
I've been searching the web for a while on this one. I've seen various suggestions but none of them seem to work. I understand that PuTTY can be configured to send different character codes for the HOME and END keys based on a setting and I can see what those codes are in the bash shell (via C-v ) and in Emacs (via C-q ). I've read that I might need to "bind" those codes someone in my .bash_profile file and/or I then might need map those codes via a keymap in my .emacs file.
Ultimately I want to be able to add something like this to my .emacs file ...
(global-set-key (kbd "C-") 'beginning-of-buffer)
(global-set-key (kbd "C-") 'end-of-buffer)
... and make CTRL- and CTRL- behave as they do in most native Windows text editors.
Has anybody been able to make this work? Please share your wisdom.
Assuming that PuTTY is indeed configured to send different sequences for HOME and CTRL-HOME (and that's a big assumption, the only terminal emulator I know which does that kind of thing is xterm), launch emacs, press CTRL-H l HOME CTRL-H l CTRL-HOME CTRL-H l. That opens an help window which will end with something like
C-h l ESC [ 1 ~ C-h l ESC [ 1 ; 5 ~ C-h l
If the last two C-h l have nothing in between, PuTTY is not sending anything for CTRL-HOME, if the two sequences between the C-h l are the same, HOME is not different from CTRL-HOME.
Now edit your .emacs:
; optional but gives a symbolic name which may be easier to work with
; and allow modes which may already know about C-home to take advantage
; of the binding
(if (not key-translation-map)
(setq key-translation-map (make-sparse-keymap)))
(define-key key-translation-map "\e[1;5~" [C-home])
; bind the key (or check before if the default binding isn't suitable)
(global-set-key [(control home)] 'beginning-of-buffer)
I figured this out. See the answer that I posted to my own question on the Emacs StackExchange forum here:
https://emacs.stackexchange.com/questions/10177/how-to-bind-ctrl-home-and-ctrl-end-to-beginning-end-of-buffer-in-emacs/10181#10181.
I am trying to bind M-<up> and M-<down> to scroll-down-line and scroll-up-line respectively as indicated here: https://stackoverflow.com/a/16229080/562139.
This is what I have in my .emacs:
;; Key bindings
(global-set-key (kbd "M-g") 'goto-line)
;; Scroll line by line
(global-set-key (kbd "M-<down>") 'scroll-up-line)
(global-set-key (kbd "M-<up>") 'scroll-down-line)
Problem:
The scroll key bindings are not taking effect, while the one for goto-line does.
When I run M-x scroll-down-line however, emacs prompts me and says
"you can run the command with <M-down>"
Note:
When I run global-set-key (kbd "M-<down>") 'scroll-up-line) or (global-set-key (kbd "M-<up>") 'scroll-down-line) directly in the mini-buffer, the bindings take effect! However, I seem to have noticed through the corner of my eye when I do the latter, that pressing M-<up> actually sends something like ESC ESC-<up>.
I'm foxed. What gives?
Note: I am running emacs 24.3 in a terminal (via iTerm on OSX with Option key mapped to ESC+) over SSH to a RHEL5 virtual machine.)
Update
I followed the suggestion in this answer and found that pressing M-<up> results in something completely different:
ESC <up> (translated from ESC M-[ A) runs the command
scroll-down-line, which is an interactive compiled Lisp function.
It is bound to <M-up>, ESC <up>.
(scroll-down-line &optional ARG)
I'm going to try binding that key sequence to the function and check the result.
Try starting Emacs without your init file: emacs -Q, and see if you can reproduce the problem.
I do not see the problem, with Emacs 24.3 in terminal mode.
What you saw briefly was probably ESC <up>, which is equivalent to M-<up>.
Did you perhaps mean to type "When I run M-x scroll-up-line (instead of down)?
I suspect that you are in some mode that gives a local binding or a minor-mode binding to these keys, which overrides the global binding. To test that, try in a buffer that is in fundamental mode. If that is the case, then to override that overriding you will need to also bind the keys in that mode's keymap.
If you cannot repro the problem starting from emacs -Q then bisect your init file (~/.emacs) recursively until you find the culprit code.
Seems key got lost in translation.
Planted a forward-paragraph at openSuse that way:
(global-set-key [(meta down)] 'forward-paragraph)
Say I have some interactive function in Emacs my-function, how can I bind it to Ctrl + RET?
I have tried with:
(global-set-key (kbd "C-RET") 'my-function)
and
(global-set-key (kbd "C-return") 'my-function)
but none of them seem to work. is this at all possible?
Always remember that kbd very conveniently accepts the exact same syntax that Emacs gives you when you ask it about a key sequence, so you never ever have to guess.
C-hkC-RET tells me:
<C-return>
therefore I would use (kbd "<C-return>")
OTOH, when running Emacs in my terminal, C-hkC-RET tells me:
C-j
because C-RET isn't a valid control character in a terminal, and therefore Emacs isn't receiving the same input that it gets in GUI mode (so I wouldn't be able to use that binding in my terminal).
This should work:
(global-set-key [(control return)] 'my-function)
It works for me, but may not in a terminal as per #phils's answer.
I've got a couple emacs keybindings as follows:
(global-set-key (kbd "C-,") 'beginning-of-buffer)
(global-set-key (kbd "C-.") 'end-of-buffer)
Recently, I realized these don't work in emacs-nox. Is it is possible to get them working, or is this just a limitation of emacs-nox?
By popular demand:
It's probably a limitation of your terminal.
Most terminals I've used don't send any keycodes at all for C-, and C-..
You can check this by executing M-x describe-key (usually bound to C-h k), and then typing C-, and/or C-.. If Emacs does nothing when you hit the keys, it's your terminal.
On my emacs(21), \C-. and \C-, don't register as keyed. I use terminal through PuTTY. The default keybindings \M-< and \M-> works fine for me for beginning-of-buffer and end-of-buffer respectively.
So either use the default keys or set some other keys if your emacs-nox does not register them as keyed in.
I'm using Viper, and I want to change its C-c and C-g to the original emacs functions. I can rebind C-g with (define-key viper-vi-global-user-map "C-g" 'keyboard-quit), but how can I rebind C-c, since it's a prefix key?
Thanks!
It may make sense for you to run M-x viper-set-expert-level with an argument of 2 ("Master"). As the viper-mode documentation explains:
2 -- MASTER: C-c now has its standard
Emacs meaning in Vi command state, so
most Emacs commands can be used when
Viper is in Vi state.
As you master viper-mode, you're meant to increase your expert-level setting gradually over time, making more Emacs features available to you (or, as the Viper documentation puts it, "To use Emacs productively, you must reach level 3 or higher").
The original binding for C-c can be set with the following:
(define-key viper-vi-global-user-map (kbd "C-c") 'mode-specific-command-prefix)
The info page for this is Prefix Keys.