6

I'm running Emacs in urxvt with zsh as shell:

~ % echo $TERM && echo $SHELL
rxvt-256color
/bin/zsh
~ %

My current problem is that I can't get Home key & End key working properly in Emacs.

Here is my .Xresources sample for keysbind:

 URxvt.keysym.Home:            \033[1~
 URxvt.keysym.End:             \033[4~

 URxvt.keysym.C-Up:            \033[1;5A
 URxvt.keysym.C-Down:          \033[1;5B
 URxvt.keysym.C-Right:         \033[1;5C
 URxvt.keysym.C-Left:          \033[1;5D

 URxvt.keysym.Meta-Up:         \033[1;3A
 URxvt.keysym.Meta-Down:           \033[1;3B
 URxvt.keysym.Meta-Right:          \033[1;3C
 URxvt.keysym.Meta-Left:           \033[1;3D

 URxvt.keysym.S-Up:            \033[1;2A
 URxvt.keysym.S-Down:          \033[1;2B
 URxvt.keysym.S-Right:         \033[1;2C
 URxvt.keysym.S-Left:          \033[1;2D

I could setup Ctrl+arrows and Shift+arrows thanks to this rxvt.el file found on the web (thanks to its author).

~ % cat ~/.emacs.d/rxvt.el
[...]
(define-key function-key-map "\033[1;5A" [(control up)])
(define-key function-key-map "\033[1;5B" [(control down)])
(define-key function-key-map "\033[1;5D" [(control left)])
(define-key function-key-map "\033[1;5C" [(control right)])
(define-key function-key-map "\033[1;2A" [(shift up)])
(define-key function-key-map "\033[1;2B" [(shift down)])
(define-key function-key-map "\033[1;2D" [(shift left)])
(define-key function-key-map "\033[1;2C" [(shift right)])
[...]

Here are the lines concerning Home & End:

~ % cat ~/.emacs.d/rxvt.el
[...]
(define-key function-key-map "\033[1~" [home])
(define-key function-key-map "\033[4~" [end])                                 
(define-key function-key-map "\033[7~" [find])
(define-key function-key-map "\033[2~" [insert])
(define-key function-key-map "\033[8~" [select]) 
(define-key function-key-map "\033[5~" [prior])
(define-key function-key-map "\033[6~" [next])
[...]

And I added these lines into my .emacs, file but without any effect:

~ % cat ~/.emacs
 [...]
 ;;default configuration for home & end key
 (global-set-key [home] 'beginning-of-line)
 (global-set-key [end] 'end-of-line)

Here is what the sudo showkey command tells me about Home & End:

 <user>@localhost ~ % sudo showkey
 [sudo] password for <user>: 
 kb mode was ?UNKNOWN?
 [ if you are trying this under X, it might not work
 since the X server is also reading /dev/console ]

 press any key (program terminates 10s after last keypress)...
 keycode  28 release
 ^[[1~keycode 102 press     //home key was pressed
 keycode 102 release
 ^[[4~keycode 107 press     //end key was pressed
 keycode 107 release
 keycode  29 press
 ^Ccaught signal 2, cleaning up...

Does anyone have any advice?

Also maybe it helps if I say that Ctrl+A works and has the same behavior that I want for Home and Ctrl+E for End.

  • What happens when you type C-h k <home> or C-h k <end>? You should see something like : "<home> runs the command beginning-of-line". Is it the case? – ffevotte Feb 4 '14 at 7:48
  • Nothing happens :) – tbenett Feb 4 '14 at 13:17
  • Have you tried to remove 2 keysym lines for Home and End from .Xresources ? – Dfr Mar 13 '14 at 6:58
  • yeah, but I need them for my shell :) Even if Ctrl-a or ctrl-e are working and do the jobs. – tbenett Mar 13 '14 at 9:15
  • I use this way under X11/Terminal and Windows7: (global-set-key (kbd "<home>") 'beginning-of-buffer) (global-set-key (kbd "<end>") 'end-of-buffer) Doesn't work for you ? – lmedinas Sep 8 '14 at 12:36
5

These worked for me:

(global-set-key (kbd "<home>") 'beginning-of-line)
(global-set-key (kbd "<end>") 'end-of-line)
  • Can you explain what the commands do? – Burgi Jul 15 '16 at 8:27
2

I think you are more advanced with emacs than I am. But, I don't use the Home and End keys at all.

I just use:

  • Ctrl+a to bring the cursor to the home of the line.
  • Ctrl+e to bring the cursor to the end of the line.

  • Alt+SHIFT+, (C-<) to bring the cursor to the home of the file/buffer.

  • Alt+SHIFT+. (C->) to bring the cursor to the end of the file/buffer.

I learned these in the default emacs tutorial.

I suppose I only found those keys practical once I had, first, mastered touch typing.

  • 1
    Yeah, it's the way I do now ;) thx for your help mate – tbenett Mar 1 '14 at 4:35
0

If you are interested in customizing rxvt keybindings for improved Emacs interoperability, you may be interested in an Emacs package I wrote, which can teach Emacs and terminals how to properly recognize all PC keyboard keys and modifier key combinations:

https://github.com/CyberShadow/term-keys

It can generate a configuration file for urxvt (and other terminals) which translate keys and key + modifier combinations to unique sequence codes, that allow them to be recognized by Emacs correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.