145
votes

I know that I can jump to the beginning and end of a line inside the OS X terminal with Ctrl+A and Ctrl + E. But I'm so used to jumping with Cmd+Right arrow and Cmd+Left arrow from my editor, that I would love to use these shortcuts for the terminal too.

I haven't found a solution with Google, so maybe here someone can help.

Update

As in the comments, I tried the solution from How to move the cursor word by word in the OS X Terminal

Unfortunately, the Terminal settings seems to not include Cmd as a Modifier Key, as you can see here:

Modifier Keys of Terminal

13
can't you adapt this ?Thomas Ayoub
I've updated my question, see above23tux
Hmmm, I don't think so. I tried it, it works with Option + right-arrow, but not with Cmd + right-arrow23tux
You're right, my fault, I've got hard days on a PCThomas Ayoub
More useful shortcuts: stackoverflow.com/a/5542996A T

13 Answers

146
votes
fn + shift + leftArrow = goto beginning of line
fn + shift + rightArrow = goto end of line

these work for me

40
votes

In the latest Mac OS You can use shift + home or shift + end

35
votes

I use a handy app called Karabiner to do this, and many other things. It's free and open source.

It's a keyboard remapper, with a lot of handy presets for many common remaps that people may want to do.

As you can see from the screenshot, this remap is included as a preset in Karabiner.

Screenshot of Karabiner preferences showing the preset to map cmd+left/right to ctrl+a/e

Hope this helps. Happy remapping!

24
votes

As setup in the terminal using vi:

The Home button on a Macbook Pro keyboard: Fn + Left Arrow.

The End button on a Macbook Pro keyboard: Fn + Right Arrow.

13
votes

For iterm2:

Go to Profiles / Open Profiles / Keys

Set Cmd + left_arrow_key to Send Hex Code 001

Set Cmd + right_arrow_key to Send Hex Code 005

This allows you to use Cmd + arrow_keys to move from beginning to end of the line.

11
votes

Here I found a tweak for this, without any third party tool. This will make the following shortcut to work:

 fn + right: to go to the end of the line.
 fn + left: to go to the beginning of the line.
  • Open terminal preferences.(cmd + ,).
  • Go to your selected theme and then to the keyboard tab.

enter image description here

  • And add a new entry as following. enter image description here enter image description here

  • That's all. Now close and check.

    Hope it helps.

EDIT: Refer to the comment by @Maurice Gilden below for more insights.

9
votes

I am not sure if this will work for you (I still use OS 10.8), but these work for my terminal:

home = move cursor to the start of the line
shift+end = move cursor to the end of the line

alt+leftArrow = move one "word" to the left
alt+rightArrow = move one "word" to the right

Hope this helps!

7
votes

fn + leftArraw or fn + rightArrow worked for me!

6
votes

For latest mac os, Below shortcuts works for me.

Jump to beginning of the line == shift + fn + RightArrow

Jump to ending of the line == shift + fn + LeftArrow

2
votes

You could download Better Touch Tools. It's an app that allows you to make custom key-bindings and shortcuts over your entire system or individual apps. Using it, you could make a shortcut in the terminal that emulates ctrl-a/ctrl-e whenever you press cmd-left/cmd-right, respectively. I definitely recommend it! I've been using it for years and I have over 50 shortcuts spread across several different apps.

2
votes

in iterm2

fn + leftArraw or fn + rightArrow

this worked for me

0
votes

This worked for me Option + left-arrow or Option + right-arrow for moving the cursor to the start or end of the line.

Mac Os Version: Catalina

0
votes

Text Navigation Shortcuts

  • Jump to beginning of a line – Command+Left Arrow
  • Jump to end of a line – Command+Right Arrow
  • Jump to beginning of current word – Option+Right Arrow
  • Jump to end of current word – Option+Right Arrow
  • Jump to beginning of all text – Command+Up Arrow
  • Jump to end of all text – Command+Down Arrow

Text Selection Shortcuts

  • Select text to beginning of a line – Shift+Command+Left Arrow

  • Select text to end of a line – Shift+Command+Right Arrow

  • Select text to beginning of current word – Shift+Option+Right Arrow

  • Select text to end of current word – Shift+Option+Right Arrow

  • Select text to beginning of all text – Shift+Command+Up Arrow

  • Select text to end of all text – Shift+Command+Down Arrow