0
votes

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.

2
I suggest you ask that question over at the SuperUser sister page...arkascha
If putty does not distinguish <home> from C-<home> and sends for both the same sequence, then what you want to achieve is impossible (at least in Emacs; you might be able to tweak putty to handle that differently). You might want to use a workaround like using a different key combination instead.Alfe
@arkascha That's definitely not the right place for it. This is config sure, but it's also code. Also, there's an emacs stackexchange which trumps superuserSquidly
@MrBones This is not an emacs question and writing a config entry is not coding.arkascha
@arkascha I disagree (to some extent) about config/code, but yeah, it's not really emacs specific either. My bad.Squidly

2 Answers

0
votes

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)
0
votes

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.