Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

The home and end keys on a MacBook Pro can be emulated with fn + left arrow or fn + right arrow. Or when certain settings are changed, with the Command (Apple) key instead of fn.

None of these works in Terminal.

As I frequently need to go to the beginning or end of the line and would also like to jump forwards or backwards by word.

How can I jump around on a line in Terminal?

share|improve this question
add comment

7 Answers 7

up vote 14 down vote accepted

Use control+a for HOME and control+e for END in Terminal.

Also use esc+f to move to the beginning of the next word and esc+b to move to the beginning of the current word. (you Must be careful about current and next)

share|improve this answer
    
perfect! what about jumping around by word? (ctrl-left and ctrl-right in windows) –  at01 Apr 27 '11 at 21:35
    
@at01 I updated my answer. –  Am1rr3zA Apr 27 '11 at 21:37
    
Another very handy one is Ctrl+l to clear the screen. –  boehj Apr 27 '11 at 21:38
2  
Who designed the keys for Terminal?!?! –  at01 Apr 27 '11 at 21:46
add comment

It sounds like you are looking for some help using readline and bash, here is an insane list of keyboard stuff modified from: http://www.math.utah.edu/docs/info/features_7.html#SEC45

Ctrla Move to the start of the line.
Ctrle Move to the end of the line.
Escf Move forward a word.
Escb Move backward a word.
Ctrll Clear the screen, reprinting the current line at the top.

Ctrlk Kill the text from the current cursor position to the end of the line.
Escd Kill from the cursor to the end of the current word, or if between words, to the end of the next word.
EscDel Kill from the cursor the start of the previous word, or if between words, to the start of the previous word.
Ctrlw Kill from the cursor to the previous whitespace. This is different than EscDelCtrla because the word boundaries differ.

Ctrld Delete the character underneath the cursor.
Ctrl_ Undo the last thing that you did. You can undo all the way back to an empty line.

And, here is how to yank the text back into the line. Yanking means to copy the most-recently-killed text from the kill buffer.

Ctrly Yank the most recently killed text back into the buffer at the cursor.
Escy Rotate the kill-ring, and yank the new top. You can only do this if the prior command is Ctrly or Escy.

share|improve this answer
    
wow, thanks! I already credited the answer, but this is great –  at01 Apr 27 '11 at 21:49
    
No problemo, I had fun just making the list work with the site. –  hobs Apr 27 '11 at 21:54
    
Wow - good effort! –  boehj Apr 27 '11 at 23:09
    
Same to you on that sharing post :) –  hobs Apr 27 '11 at 23:31
    
this is invaluable - thanks - I wish this was available as a printable file somewhere! –  matt b Jun 13 '11 at 17:09
show 1 more comment

To answer the one about how to get the beginning or end of the line, it appears that by default Terminal maps these keys to it:

  • shift+home → beginning of line, equivalent to the "home" key in normal terminals
  • shift+end → end of line, equivalent to the "end" key in normal terminals

If you want home and end to work the "normal" way (and not require shift), go to [Terminal menu] → Preferences → Settings tab → Keyboard sub-tab.

Then modify keys to be this "send string to shell"

  • home: \033[H
  • end: \033[F

(you can get the \033 part by hitting the escape key within the edit dialog, if you need to add it).

Then home and end will work like normal again.

Feel free to modify this answer to add more useful key bindings, as it is a community wiki.

share|improve this answer
add comment

For those that prefer to use the arrow keys, hitting fnShift+Left Arrow will take you home on the command line. Similarly, fnShift+Right Arrow will take you to the end.

share|improve this answer
add comment

The other answers are great and more portable, but here's "the OS X way" for a regular keyboard (which is opposite of many other terminals). Try the following:

ShiftHome - Beginning of Line
ShiftEnd - End of Line

From http://www.greenend.org.uk/rjk/tech/macbits.html

share|improve this answer
add comment

You can move one word at a time with option+left and option+right.

Regarding using home and end, Terminal's default bindings are the following:

  • shift+home → jump to beginning of line
  • shift+end → jump to end of line
  • home → scroll to top of scroll-back buffer
  • end → scroll to bottom of scroll-back buffer

In many other terminal apps (on multiple platforms), those modified and unmodified pairs are reversed (i.e. naked home and end are used to jump around the current line and the modified versions (whether by shift or something else) are used to navigate the scroll-back buffer). You can reverse Terminal's bindings to work that way if you wish by doing the following:

Go to Terminal menu → Preferences → Settings tab → Keyboard sub-tab.

Then modify the key–action pairs to be the following:

  • ↖︎: Send text: \033[H
  • ⇧↖︎: Scroll To Top
  • ↘︎: Send text: \033[F
  • ⇧↘︎: Scroll To Bottom

Note: \033 is entered into the text-to-be-sent box in the Edit dialog by pressing the escape key.

While there, you may want to similarly swap the bindings of modified and unmodified page up and page down, to keep things consistent: pressing a navigation key with shift represents a command to Terminal itself (to navigate the scroll-back buffer like a document), while pressing one without sends the key-press through to whatever's running within it (e.g. bash, less, nano, screen, etc.). The key–action pairs for that are:

  • ⇞: Send text: \033[5~
  • ⇧⇞: Scroll Page Up
  • ⇟: Send text: \033[6~
  • ⇧⇟: Scroll Page Down
share|improve this answer
add comment

here's the list in printable form, as desired :)

http://pastebin.com/uCqwn7qs

I also fixed a "bug" in the description. This is what you could originally read in the instructions:

ESC-d Kill from the cursor the start of the previous word, or if between words, to the start of the previous word.

This smells badly like a cut-and-paste mistake, since both partial sentences tell the very same thing. Telling from plain logic, first half must actually read "from the cursor to the start of the current word".

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.