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).
One last problem to clean up. Both PuTTY via ssh and now Terminal.app didn't behave nicely with the new key bindings - they just inserted a twiddle at the prompt. However, I was fairly convinced that the bindings I was using were correct. The fix is to bind the functionality of those keys to the correct editor commands in tcsh. I did this by inserting the following code into my ~/Library -> init -> tcsh -> rc.mine file (see other hints for setting that up). It might be more correct to put it into ~/Library -> init -> tcsh -> login.mine ... anyway, here it is:
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.
Enjoy!