[macos] OS X Terminal shortcut: Jump to beginning/end of line

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

This question is related to macos terminal keyboard-shortcuts

The answer is


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.


in iterm2

fn + leftArraw or fn + rightArrow

this worked for me


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


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!


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

these work for me


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


fn + leftArraw or fn + rightArrow worked for me!


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.


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


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.


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.


Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to terminal

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave Flutter command not found VSCode Change Default Terminal How to switch Python versions in Terminal? How to open the terminal in Atom? Color theme for VS Code integrated terminal How to edit a text file in my terminal How to open google chrome from terminal? Switch between python 2.7 and python 3.5 on Mac OS X

Examples related to keyboard-shortcuts

Collapse all methods in Visual Studio Code Is there a keyboard shortcut (hotkey) to open Terminal in macOS? Jupyter/IPython Notebooks: Shortcut for "run all"? Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse? How do I duplicate a line or selection within Visual Studio Code? How do I search for files in Visual Studio Code? OS X Terminal shortcut: Jump to beginning/end of line window.close() doesn't work - Scripts may close only the windows that were opened by it Comment shortcut Android Studio Column/Vertical selection with Keyboard in SublimeText 3