189

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

hippietrail
  • 15,848
  • 18
  • 99
  • 158
23tux
  • 14,104
  • 15
  • 88
  • 187

16 Answers16

184
fn + shift + leftArrow = goto beginning of line
fn + shift + rightArrow = goto end of line

these work for me

hygoh2k
  • 2,060
  • 2
  • 12
  • 7
  • 41
    I didn't need to hold the shift key. `fn + leftArraw` or `fn + rightArrow` worked for me. Maybe it helps! – Bharat Gupta May 21 '18 at 03:52
  • 13
    @BharatGupta fn+leftArrow works in some terminal applications (e.g. VI), but doesn't work in the terminal command line. – hygoh2k May 28 '18 at 09:16
  • 9
    Using iTerm2, fn+left and fn+right work without shift. With shift, they don't work. ctrl+a and ctrl+e also work. – bhekman Jul 23 '18 at 22:49
  • 8
    I'm a new Mac user and I'm disgusted by how hard everything is in Mac vs Windows! The hardware is good, but the software is horrible (i.e. not user friendly.) – doctorram Sep 09 '19 at 20:12
  • 2
    If you are new on Mac think simple, coz when you use windows for long term, you are used to always use complicated path... with Mac you have to think very simple... and most of time you got it. It was like that for me when I switch for PC to Mac – Supernini Dec 15 '19 at 23:35
  • Nice, only problem on mac usb/bluetooth keyboards is the `fn`key above the arrow keys. For people who play the guitar pressing that 3 buttons might work well :), so the default option `^ + e` might be better. – Adam Oct 16 '20 at 14:45
  • 1
    It's not simple though. A lot of things are extremely inconsistent and not user friendly. This very question is an example of one. Navigation and text manipulation keyboard shortcuts are completely different between different applications. – theferrit32 Feb 19 '21 at 22:41
  • I have a windows keyboard. Throw it away because no answers here work? But the OPs solution with Ctrl+a and Ctrl+e does it. – Timo Mar 24 '22 at 14:28
  • 1
    @Supernini Windows: press `Home` key which on some laptops will require also pressing the Fn key, but will always be labelled. Mac: come to StackOverflow to find answer. To paraphrase the old ads, 'Define Simple'. – Colin Bernays Jun 30 '22 at 00:14
  • In Monterey 12.6, it doesn't work.. – Changdae Park Oct 21 '22 at 12:14
71

Control + A for goto the beginning and Control + E to goto the end

Edual Feliz
  • 892
  • 6
  • 7
52

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

elad silver
  • 9,222
  • 4
  • 43
  • 67
38

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!

Aaron Wallentine
  • 2,318
  • 24
  • 22
  • 2
    Now it supports Sierra and even higher. Here's the link to some pre-defined rules from [Karabiner website](https://pqrs.org/osx/karabiner/complex_modifications/). – JavaNoScript Jul 16 '19 at 13:55
  • In @JavaXu's link in the comment directly above me, search for `Navigation in Terminal Apps` to find the rule you need to import. – derpedy-doo May 27 '20 at 05:34
  • @electrovir I can't find that rule in the link. Is it gone now? – jaquinocode Sep 04 '21 at 06:27
  • 3
    @jaquinodev the `Navigation in Terminal Apps` shortcuts config seems to have been replaced with `Keyboard shortcuts for Terminal apps` which does _not_ have the shortcuts needed for this question. Since I still have the configs laying around [I uploaded it to GitHub (with instructions) here](https://github.com/electrovir/karabiner-elements-terminal-navigation). – derpedy-doo Sep 14 '21 at 02:35
29

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.

Abhishek saharn
  • 927
  • 9
  • 23
Thinkhear
  • 368
  • 3
  • 4
  • 3
    This question was about the Mac OS terminal, not `vi`. `vi` is an application that can be run inside a terminal. – theferrit32 Feb 19 '21 at 22:43
24

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.

Community
  • 1
  • 1
Abhishek saharn
  • 927
  • 9
  • 23
  • 15
    That will just enter "001" or "005". The backslash is missing and I could not find any way to manually add it. What you can do however is, press Ctrl+A for "\001" and Ctrl+E for "\005" while inside the text box. – Maurice Gilden Nov 08 '19 at 10:38
  • 4
    This should be the absolute correct answer. All of the 3rd party apps are either broken or no longer maintained and fn+shift+leftArrow no longer works on Mojave. – Salyangoz Dec 09 '19 at 19:09
  • 6
    This worked brilliantly. However, I selected "End" rather than "Page Down" for the fn + right arrow mapping. – nedblorf Jun 26 '20 at 13:21
  • Thank you brethren Abhishek, Maurice, Salyangoz and nedblorf, you the best. The only thing which left to figure out for me is to enable this functionality when working from terminal apps like the MidnightCommander (espetially when panels are switched off with the Ctrl+O). – sqr163 Nov 13 '21 at 20:19
  • On my windows keyboard, I now have pos 1 as 'go to begin of line' and end as 'go to end of line' which is what I want. I could enter backslash, but not one backslash but two so I followed Maurice. – Timo Mar 24 '22 at 14:39
  • @Maurice Gilden is the answer – Changdae Park Oct 21 '22 at 12:22
18

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.

Abhishek saharn
  • 927
  • 9
  • 23
Timmy Von Heiss
  • 2,160
  • 17
  • 39
  • as per @bhekman's comment: "Using iTerm2, fn+left and fn+right work without shift. With shift, they don't work. ctrl+a and ctrl+e also work." – Alexander Suraphel Sep 01 '19 at 17:10
  • I don't see `cmd` as a modifier key option, same as in the original question – derpedy-doo May 27 '20 at 05:28
  • @electrovir just hold it down and press the arrow keys – Timmy Von Heiss Jun 01 '20 at 16:57
  • See "Unfortunately, the Terminal settings seems to not include Cmd as a Modifier Key, as you can see here" in the original question. I have the same problem. My comment was about creating the key setting, not executing it. – derpedy-doo Jun 02 '20 at 00:54
  • @electrovir it sounds like you are in the wrong place. there is no modifier. open iterm. go to preferences. go to profiles. press the "+" button to the left of "Load Preset". There are two fields: "Keyboard Shortcut" and "Action" for keyboard shortcut hold command press the left arrow key. then for action -> "send hex code -> 001 " – Timmy Von Heiss Jun 02 '20 at 02:07
  • Ah, I skipped over your "For iterm2" qualifier. I just assumed this was for Terminal since that's what the question was for :) Sorry about the confusion. – derpedy-doo Jun 02 '20 at 16:38
12

As per the official website of Apple

control + A - Move to the beginning of the line

control + E - move to the end of the line

terminal shortcuts by Apple's official site

Koushik Das
  • 9,678
  • 3
  • 51
  • 50
  • thank you, i accidentally came across `ctr + A` and I was looking for the opposite :) – stue Sep 07 '22 at 00:29
8

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!

noufalcep
  • 3,446
  • 15
  • 33
  • 51
Boncrete
  • 146
  • 1
  • 5
  • 1
    In 10.12 Sierra, it looks like it's shift + home to go to the beginning. the others listed here work as listed. – Chris Jun 13 '17 at 14:39
8

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

Tejas Niturkar
  • 181
  • 2
  • 3
7

You could download Better Touch Tool.

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.

enter image description here

I definitely recommend it!
I've been using it for years and I have over 50 shortcuts spread across several different apps.

Bloke
  • 2,229
  • 3
  • 22
  • 27
Jacob Marshall
  • 182
  • 2
  • 11
7

fn + leftArraw or fn + rightArrow worked for me!

Akshay Paliwal
  • 3,718
  • 2
  • 39
  • 43
7

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+Left 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+Left 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

Abdur Rahman
  • 1,420
  • 1
  • 21
  • 32
2

in iterm2

fn + leftArraw or fn + rightArrow

this worked for me

Ajith
  • 39
  • 2
1

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

Prakash P
  • 3,582
  • 4
  • 38
  • 66
1

i have the same issue on MacOS 12 (Monterey) - want to go to beginning and end of the line with fn + arrow keys. When you are trying to write '\' in that text field, it becomes '\\' (with escape). You need to paste this text (copy from some text editor, o from terminal) \001 (home) and \005 (end) in field.

enter image description here