Goal: It annoys me that page up, page down, home and end keys do not function as editor keys but instead scroll the terminal's scrollback. I often use vi, and remotely work via ssh. Using PuTTY from a PeeCee, the key bindings for page up and page down worked sort-of the way I wanted, but not quite. Here's how to fix it for both remote access and local access via Terminal.app.
Note:
I use tcsh, so the hint gets things working there. Parts may not work for bash - or probably will require a minor tweak. I have my terminal type set to xterm-color (which I believe is the default). Altering that may also affect whether the hint works.
Remapping keyboard in Terminal.app
A previous hint describes how to paste escape-sequences into Terminal.app's Window Inspector -> Keyboard section. I'm not going to repeat that here, except to summarize that you can do the following for tcsh (which the hint's comments seem to imply won't work - it does, though):
set echo_style=both
echo -n "\e[1~" | pbcopy
The key is making sure you've got echo_style set to both. It's kind of useful, so you may want it in a startup file. That will get the sequence <esc>[1~ on the clipboard. The defaults for Terminal.app are:
end -- <scroll to end of buffer>
home -- <scroll to start of buffer>
pg up -- <scroll to previous page of buffer>
pg down -- <scroll to next page of buffer>
shift + end -- "<esc>[F"
shift + home -- "<esc>[H"
shift + pg up -- "<esc>[5~"
shift + pg down -- "<esc>[6~"
My intention was to swap the shifted and non-shifted functionality listed above. However, I descovered that the home and end keys bindings didn't work well with vi, and that furthermore, page up and page down didn't work well with tcsh's command line entry (they put simply a ~ on the prompt). Hmmmph. Some amount of digging later reveals that the codes for page-up and page-down are in fact correct, but that the end and home key combos are not (they were using some badly supported vt100 emulation codes). The correct ones are:
home -- "<esc>[1~"
end -- "<esc>[4~"
So I performed the swap, but substituted the new key codes for home and end, thus you have:
end -- "<esc>[4~"
home -- "<esc>[1~"
pg up -- "<esc>[5~"
pg down -- "<esc>[6~"
shift + end -- <scroll to end of buffer>
shift + home -- <scroll to start of buffer>
shift + pg up -- <scroll to previous page of buffer>
shift + pg down -- <scroll to next page of buffer>
Having set these up for a window, don't forget to click use as defaults to make the setting stick! These bindings work perfectly with vi - you can use page up, page down and home and end when editing your text and they work as expected (and now match what I had when using PuTTY on the PeeCee).
if ($?interactive) then
bindkey "\e[5~" <tt>vi</tt>-word-back
bindkey "\e[6~" <tt>vi</tt>-word-fwd
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
endif
Now I have the correct functionality via remote ssh and locally in Terminal.app for vi. I also have useful bindings locally and remotely for tcsh's command-line.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20040401033846410