10

I installed MacPorts on OS X 10.5 and I found out that when I connect to the computer using SSH and use mc - Midnight Commander - the HOME and END keys do not work.

I have to mention that I'm using putty and I am able to use the keyboard very well on Linux machines like Fedora, Ubuntu,...

Here is putty keyboard configuration (a configuration I found to be optimal over time):

  • Backspace key: 127
  • Home/End keys: Standard
  • Function keys: Xterm R6
  • Cursor keys: Normal
  • Numpad: normal
  • Terminal type string: xterm-color

I'm looking for a command line solution/script that does these changes, this make much easier to create a prepare OS script for configuring a new OS.

5 Answers 5

12

The keyboard mappings for home and end in Terminal.app are not direct, but you can fix them. To get them to work directly, go to Terminal -> Preferences... -> Settings screen -> Keyboard and then find the lines for these keys and click the edit button for them (or add them if they are missing for some reason).

Be careful to not have any leading or trailing spaces as well for these.

home key code:

\033[H

end key code:

\033[F

page-up key code:

\033[5~

page-down key code:

\033[6~

Screenshot1

Screenshot2

4
  • I wasn't able to enter the sequences because backslash is auto-translated to double-backslash (OS X 10.6). Also, I would prefer a script/command line for doing these settings (if possible).
    – sorin
    Mar 9, 2010 at 6:52
  • @Sorin Strange, I am running OS 10.6 and that's the OS I did my screenshots with, but then again I made my profile on 10.5. It appears that typing in the control sequence into TextEdit and then doing a copy and paste into the field works fine. Mar 11, 2010 at 7:10
  • Legend, thanks! PageUp and PageDown now work properly in vim :-) Dec 17, 2013 at 4:17
  • 1
    \033 is entered by pressing the escape key
    – jlsecrest
    Jun 26, 2014 at 7:52
6

The actual question was how to use Home and End keys with PuTTY when logged into OSX using ssh.

First, I changed the settings in the OSX Terminal.app preferences according to this link. It worked for me to fix Home and End keys for usage on desktop. However when logged into OSX remotely with PuTTY, Home and End keys still didn't work. So I modified PuTTY terminal as below:

Go to PuTTY configuration > Terminal > Keyboard
find "The function keys and keypad"
instead of
ESC[n~
choose
SCO
click Apply.

Your Home and End keys should work properly now on your PuTTY terminal when you are logged into OSX.

You can set and save different settings for your different sessions. When you login to other type machines you may use standard PuTTY setting.

2
  • Setting "Function keys and keypad" to "SCO" fixes the home/end keys, but unfortunately breaks the F-keys in Midnight Commander... Sep 13, 2015 at 1:02
  • This repairs Home and End but changes the Del key to Backspace.
    – cweigel
    Feb 6, 2018 at 15:17
2

Hold down the shift key for Home/End PgUp/Pg down in Terminal.app in order to not let Terminal use these keys for the scrollback. This way (with shift) Terminal will pass the keys on to the application running in the window.

1

This doesn't directly answer the question, but may be helpful to others that landed here from searching:

I ran chsh -s /bin/bash to change my shell from zsh to bash which appears to correctly support home and end keys over SSH without fiddling.

-1

I had a similar problem after switching to the Mac. In OS X, Home and End take you to the start and finish of a document respectively. Think of them as Page Up and Page Down on steroids.

To do the equivalent to the Windows usage of Home and End, use Command+Left Arrow and Command+Right Arrow.

1
  • 1
    Sorry but this a different problem and is not related to the one specified to you.
    – sorin
    Jul 31, 2009 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .