Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way of using normal keyboard text selection with a terminal on MacOS?

Tags:

terminal

macos

For the last ~10 years I've been used to manipulating text with the alt// keys. For instance, alt+ to jump back a word instead, alt++ to select that word, + to jump to the end of line, etc.

I understand that terminals have different conventions and historically came first, but I'm used to these shortcuts, they work great and work everywhere else. Is there any way of getting the same controls for selecting and manipulating text in the terminal?

I have seen the following questions:

  • How to move the cursor word by word in the OS X Terminal
  • How do I clear/delete the current line in terminal?

But they only address moving the cursor, and not selection.

like image 672
yawn Avatar asked Jun 10 '21 18:06

yawn


People also ask

How do I use the Mac keyboard in Terminal?

1) If you have the Spotlight Search button in your menu bar, click it. Otherwise, you can use the keyboard shortcut Command + Space. 2) Type in “Terminal.” 3) You should see the Terminal application under Top Hit at the top of your results.


2 Answers

Depending on the macOS version - your default shell may be zsh.

Shortcuts options are ctrl + a/e to move to beginning/end of line and esc + W/B to move one word backward/forward

Other popular alternatives are -

a. bash - with the shortcuts listed in the answer by @Hossein Amiri

b. iterm2 - From - https://coderwall.com/p/a8uxma/zsh-iterm2-osx-shortcuts

Put this in your .zshrc

bindkey "[D" backward-word
bindkey "[C" forward-word
bindkey "^[a" beginning-of-line
bindkey "^[e" end-of-line

And set iterm preferences.
like image 66
moi Avatar answered Oct 21 '22 21:10

moi


Moving the cursor:

Ctrl+A Go to the beginning of the line (Home)
Ctrl+E Go to the End of the line (End)
Hold the Option key option and click on the current line = Jump Backwards
Ctrl+P Previous command (Up arrow)
Ctrl+N Next command (Down arrow)
Hold the Option key option and click on a previous line = Jump upwards
Ctrl+F Forward one character
Ctrl+B Backward one character
Alt+B Back (left) one word or use Option+
Alt+F Forward (right) one word or use Option+
Ctrl+xx Toggle between the start of line and current cursor position

More information : https://ss64.com/osx/syntax-bashkeyboard.html

like image 40
Hossein Amiri Avatar answered Oct 21 '22 20:10

Hossein Amiri