En Fr
Web/database development and more...
« How to get AC-3 5.1 surround sound on your MacSecure SSH private keys on Mac OSX 10.5 »

Mac OSX Terminal Page Up/Down + Home/End of line

12/21/08

English (US) Mac OSX Terminal Page Up/Down + Home/End of line

Permalink 04:04:04 am, by Francois Planque Email , Categories: Mac stuff

In order to get page up and page down to work properly under Mac OSX Terminal, as well as the home and end of line, you need to go to Preferences and then Keyboard and configure the right escape key sequences:

Key Escape Sequence
Home \033[1~
End \033[4~
Page Up \033[5~
Page Down \033[6~

37 comments

Comment from: andrew [Visitor]
andrewdoesn't seem to work for me. i just get a beep and ~ left on the screen. any hints?
01/07/09 @ 22:28
Comment from: Jorge Lobo [Visitor] Email
Jorge LoboI have a new macbook (jan2009) and could not find the place to insert escape sequences in the preferences/keyboard options...

I use space to page down, the mac two key page up and down scrolls the window, not the terminal text
03/16/09 @ 22:57
Comment from: Brian [Visitor]
BrianThis worked for me, but was already set up on my 10.5 installation. It was already set up for Shift-page up/page down.
04/18/09 @ 17:55
Comment from: theman [Visitor]
themanTry this in the Terminal -> Preferences -> Keyboard widget:

CTRL-A -- this is to go to the beginning of a line in Bash (set this to the 'Home' key)
CTRL-E -- this is to go to the end of the line in Bash (set this to the 'End' key)

The first combo will produce: \005
The second combo will produce: \001

Don't worry, it works in 10.5.x. This also works in the C Shell ('csh'), so if you are used to using it this will work there as well.
05/12/09 @ 04:26
Comment from: Mirek Rusin [Visitor] Email
Mirek RusinWorks perfectly, thanks a lot!
05/19/09 @ 12:21
Comment from: Pedro [Visitor]
PedroGreat! Works perfect for me!
07/23/09 @ 17:25
Comment from: Paddy [Visitor]
PaddyWow ....this worked for me too on Mac OSX 10.5.9
07/23/09 @ 18:35
Comment from: Richard P. Spillane [Visitor]
Richard P. SpillaneAlternatively, if this has problems, or is bash specific (doesn't work in tcsh) you can try this alternative solution:

Terminal->Preferences->[Settings]->[Keyboard]:

Find end, home, pg up, and pg down (the list is alphabetically sorted).

First double click 'end' and a prompt comes up that lets you remap the key, for 'Action' select 'send string to shell:' and then click on the entry field.

Press 'Esc' which emits '\033' then type '[4~' after it, so the text field should now show: "\033[4~". Click 'OK'.

Now you should be able to remap the other keys if you know the key codes, by pressing 'Esc' to emit \033. The codes for each of the keys are:

end \033[4~
home \033[1~
page down \033[6~
page up \033[5~

You will want to add 'Shift-pgdwn/pgup' to ask the buffer to scroll up and down. Do this by clicking '+' and adding 'pg down' with the 'Shift' modifier and then select 'scroll to next page in buffer', and do the opposite for pg up.

I believe this is the optimal fix.
07/24/09 @ 07:46
Comment from: Jaap Blom [Visitor]
Jaap BlomThanks a bunch these are indeed the optimal settings!
08/27/09 @ 15:29
Comment from: mihai [Visitor] Email
mihaiI've found that the home and end keys don't work with bash, but they work with mc (through ssh). To fix them for bash, I used this inputrc fix: http://linuxart.com/log/archives/2005/10/13/super-useful-inputrc/

Cheers!
09/24/09 @ 00:24
Comment from: Alex [Visitor] Email
AlexI tried doing this but it didn't work (OSX 10.5.8). Instead of going to the end of the line, I get a "BEEP" and a tilde (~) appears in the term window.

Would love to get this working if anyone knows off the top of their head what I'm doing wrong.
11/06/09 @ 17:54
Comment from: Warren Houghteling [Visitor]
Warren HoughtelingYou're my hero! Not having these keys work as I'm used to in a terminal window was driving me crazy.
12/08/09 @ 19:47
Comment from: Davis Chord [Visitor]
Davis ChordThanks for the heads-up on this!
01/22/10 @ 20:19
Comment from: norman [Visitor]
normanTry
Key Escape Sequence
Home \033OH
End \033OF

The O's are captital as in OOPs, they are not zero's. This is straight from termcap for xterm and works for both the bash shell and vi/vim

01/27/10 @ 14:48
Comment from: Adub [Visitor]
AdubGreat! Thanks for this. I had to copy and paste the text but it worked flawlessly after that.

Thanks again!
02/02/10 @ 18:40
Comment from: C [Visitor]
CThanks!!! The optimal setting above was my solution since i come from *nix and work alot with vi. This WAS driving me crazy. No more, yes!
02/17/10 @ 21:17
Comment from: the donco [Visitor] Email
the donconorman's comment with the OH/OF sequences finally worked for me on:
Mac OSX 10.6.2
17" Macbook Pro (built-in keyboard)

Also works via Synergy client (on Mac), connected to [Ubuntu] Linux (running server) w/Microsoft Natural Keyboard Pro


Everything works about right....except in terminal, where the command[/alt] and ctrl keys are flipped -- I flipped them in the mac preferences so that ctrl+x/c/v would work without a bizarre reach, and now I have to "alt+c" running commands to kill them. Because I do most my terminal work on Linux, this is [barely] acceptable, but any insight on how to have the best of both worlds would be appreciated -- i.e.: ctrl+c/copy in email and ctrl+c/cancel in terminal.


Regards,
-the donco

LiveCloud.com - Blog. Get Social. Take Control.
LiveCloud is a Social Strata Venture
02/24/10 @ 20:36
Comment from: Martin Kovachev [Visitor]
Martin KovachevThank you SOOOOOOOOOOOOOOOOOOOOO much!!!!! :))

I was getting crazy scrolling char by char until i get to the end of the console line...
03/21/10 @ 18:27
Comment from: carnator [Visitor]
carnatorThank you Francois! however in OSX (10.6.2) the end/home keys did not work the same way for the terminal and vi.

@norman [Visitor] your bindings worked perfectly!
03/26/10 @ 00:27
Comment from: James [Visitor]
JamesFn+Shift+Up = Page Up

Fn+Shift+Down = Page Down
06/02/10 @ 19:27
Comment from: Neil [Visitor]
NeilNorman (visitor)'s mappings also worked for me on a macbook pro with OS 10.6.3.

What I really want is for command-left / command-right to do that, like they do in every other mac app.
06/16/10 @ 13:25
Comment from: Doug [Visitor]
DougYou are the man!!! Thanks worked like a charm! Mac OS X 10.6.4
09/21/10 @ 16:22
Comment from: Keith [Visitor]
KeithThanks!

Now... how the hell can I get these keys to work in textedit. AND Home and End keys do not work in my browser address bars. Is there a modifier? This is driving me nuts. Works fine on windows if I want to jump to the end or beginning of a url in the browser address bar.
12/17/10 @ 21:06
Comment from: Joaquin [Visitor]
JoaquinWOW! 04:04:04am. Nice timing!
01/14/11 @ 20:55
Comment from: Marius [Visitor]
MariusIf you find that this does not work on your command-line, keep in mind that your shell may just not know what to do with those command, but all those key sequences work pretty well in VIM editor.

For you to tell your shell how to interpret them, you either need to create a matching custom termcap entry, or use an existing one with a lot of matching capability.

For instance, Home and End does not work for me on my terminal when using vt220, xterm, or color-xterm... but when I do a "export TERM=linux" it works.

PgUP and DOWN still don't have a function for me on my command-line, but that's ok, since I don't know what it is supposed to do anyway.



01/26/11 @ 20:57
Comment from: Colin [Visitor]
ColinActually it should be

Fn + Up Arrow = Page Up
Fn + Down Arrow = Page Down
02/04/11 @ 00:49
Comment from: Paul [Visitor]
PaulThanks mate! worked perfectly!
03/05/11 @ 06:07
Comment from: Tim [Visitor]
TimThanks alot mate. I've been looking for this desperately. As a first-time Mac user, I didn't know the Fn + direction keys were the Home, PageUp, End, PageDown keys.
03/13/11 @ 10:46
Comment from: Michael [Visitor]
MichaelGood stuff mate, worked a treat. Vim over SSH is now useable. \:D/
03/29/11 @ 22:07
Comment from: Shez [Visitor]
Shezholding function and shift and pressing down also works.
04/11/11 @ 10:00
Comment from: Mike Schroder [Visitor]
Mike SchroderThanks!~

This is still being found, and was very helpful.
04/19/11 @ 03:48
Comment from: Kate [Visitor]
KateThank you! The Control A & E short-cut did the trick!
04/21/11 @ 23:56
Comment from: Seth [Visitor]
Seththanks, that worked. I live in the terminal and the home/end keys were killing me.
11/03/11 @ 00:28
Comment from: steve [Visitor] Email
steveThanks......worked very well on Lion for me... it was driving me nuts, Ubuntu seems to include a lot of VIM functionality....
11/28/11 @ 04:55
Comment from: kyle renfrow [Visitor]
kyle renfrowIn order to get all four keys working I had to use a combination of the answer and comments:

for home and end: select 'send to shell' and press ctrl + a, and ctrl + e respectively.

for page up/down: select 'send to shell' and press the escape button followed by [5~ and [6~ respectively.

home \001
end \005
page up \033[5~
page down \033[6~
12/01/11 @ 05:45
Comment from: Rohaiza [Visitor]
RohaizaI try all the above suggestion, but does not worked to my macbook pro (parallel)..any hints? TQVM
01/08/12 @ 18:56
Comment from: Kyriacos [Visitor]
KyriacosThanks for posting! Home and End keys do not work, but at least PageUp and PageDown are working great. (Mac OS X 10.7.2)
01/10/12 @ 16:31