Hotkeys for navigating the Terminal in OS X

NewTerminalIconXIf you regularly use the OS X Terminal, then there will undoubtedly be times you encounter the limitations of the cursor. For instance, if you have a relatively large command entered but need to edit a small typo in the middle of it, then you might resort to using the arrow keys to move backward character by character until you get to the part you wish to edit. If you have been frustrated by this approach, then you might benefit from a number of relatively undocumented hotkeys that can greatly enhance your handling of text at the point of Terminal cursor.

These hotkeys are basically the classic Unix Terminal navigation hotkeys, which have simply been preserved in this environment when Apple implemented it in the Mac OS.

As with any set of commands, they may take a while to become second-nature, but with practice, the relevant ones for your workflow should help speed things up.

Command Management

  • control-C (new line and cancel current input without executing)
  • control-J/M (execute the currently entered command)
  • control-P (prior command)
  • control-N (next command—only if not at the end of the history)

Cursor Placement

  • control-F (move the cursor forward one character)
  • control-B (move the cursor backward one character)
  • control-A (put cursor at start of the current line)
  • control-E (put cursor at end of the current line)

In addition to these, you might have some use for some of Apple’s hidden hotkeys and shortcuts that work in the Terminal. I have found these to be perhaps the most useful of all, especially since they allow for use of the mouse cursor.

  • option-left/right arrows (jump to beginning or end of word)
  • option-click (move cursor to the clicked character)

Text Deletion

  • control-K (delete all text from the cursor’s position to the end of the line)
  • control-U (delete all text from the cursor’s position to the beginning of the line)
  • control-W (delete all text to the beginning of the current word)
  • control-D (delete current character; also exits the current shell if the line is empty)
  • control-H (delete the character immediately before the cursor)
  • control-Y (delete enter previously deleted text using the above commands)

Miscellaneous

  • control-L (clear the display)
  • control-T (swap cursor character with prior one)

Finally, one of frustration you might have with the Terminal is the inability to scroll up or down in various text editors and other programs that display content you might need to browse through. While there are keys in these editors for jumping forward and backward, in the upcoming OS X Yosemite Apple appears to be implementing the scroll function where the Terminal will move up or down by one line in rapid succession as a response to a scroll gesture in the Terminal. This effectively introduces a smooth scrolling feature that can help you center content on screen.