Mousing and Page-Up/Down in Terminal for Mac OS X

20

21

Compared to *nix, Terminal.app seems pretty lame. How can I get it to:

  • Send Page-Up/Down to an application, instead of just scrolling the terminal output
  • Mouse around in vim. set mouse=a isn't helping.
  • All of the above while SSH'd into another machine

Nick Retallack

Posted 2010-01-26T23:33:56.813

Reputation: 1 436

Answers

33

OMG facepalms apple still hasn't taken care of this. I would get calls from Tier 1 noobs all day when I worked at apple.

  • Open Terminal.app
  • Open the Preferences window (CMD+,)
  • Click the Settings tab
  • Select your current Settings theme, and click on the Keyboard tab
  • Edit (or Add) the entry for Home:
    • Set Action: to send string to shell:
    • Set the string to \001 (or press Ctrl+a)
  • Edit (or Add) the entry for End:
    • Set Action: to send string to shell:
    • Set the string to \005 (or press Ctrl+e)
  • Edit (or Add) the entry for Page Up:
    • Set Action: to send string to shell:
    • Set the string to \033[5~ (copy and paste this in)
  • Edit (or Add) the entry for Page Down
    • Set Action: to send string to shell:
    • Set the string to \033[6~ (copy and paste this in)
  • Close the settings window.

There you go. Terminal should be ready to use the Home, End, Page Up, and Page Down keys as expected by Windows/Linux users.

SSH into your favorite Linux server, open nano, vi, or emacs and enjoy.

If home or end keys don't work in vim try these:

  • Home: \033[7~
  • End: \033[4~

As for the mouse issue, I'm not sure if Termminal.app supports xterm mouse reporting. Supposedly it needs that to work. iTerm is an alternative terminal program that support mouse reporting. MouseTerm is a hack to add mouse reporting to Terminal.app but I've not tried it and don't know how well it works

You can also install X11.

Once you do one of those three things you should be able to use ssh with set mouse=a.

Kelbizzle

Posted 2010-01-26T23:33:56.813

Reputation: 1 808

1Awesome answer. I've been wrestling with this for years, and taken to using C-u/d in vim and "/scrollback goto +/-30" in irssi for so long. – Nick Retallack – 2010-01-27T01:25:35.123

Thanks! it's a huge problem for alot of users. Glad I could help! – Kelbizzle – 2010-01-27T01:27:44.150

For me, the codes \033OH for Home and \033OF for End worked better. (at least in less) – Lars Nyström – 2017-12-05T10:37:02.070

This is also super-handy for adding a one-handed pageup/pagedown (on laptops, there is no Fn key on the right, so shift+Fn+arrow is a two-handed operation). I bound option+uparrow to \033[5~ and option+downarrow to \033[6~ for page up/page down, for happy one-handed text scrolling. – Ether – 2012-08-11T19:11:51.983

4

With regards to Page Up/Down and Home/End, simply hold down the shift key to send those to the application. Otherwise remapping the keys as Kelbizzle described will completely do away with Apple's idea of what's most important to scroll through (i.e. their scrollback).

Cairo

Posted 2010-01-26T23:33:56.813

Reputation: 434

1

Within Terminal mc (midnightcomander) works with Fn+Shift+UpKey and Fn+Shift+DownKey

myset

Posted 2010-01-26T23:33:56.813

Reputation: 241

0

Correct key codes:

home key code:

\033[H

end key code:

\033[F

page-up key code:

\033[5~

page-down key code:

\033[6~

Source with screenshots: https://superuser.com/a/33370

Alexander Ushakov

Posted 2010-01-26T23:33:56.813

Reputation: 111

0

In 10.10 Yosemite (not sure about previous versions) you can scroll down using the trackpad or a mouse the same way you would a webpage. Put the mouse over the Terminal window, and scroll using the mouse wheel or two fingers on a touchpad.

TheKarateKid

Posted 2010-01-26T23:33:56.813

Reputation: 195