8

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:

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

Jonathan
  • 1,955
  • 5
  • 30
  • 50
yawn
  • 422
  • 1
  • 5
  • 21
  • 1
    Do you mean in editor like vi? Or do you mean on the command line? May I also suggest you use iTerm2 and see https://superuser.com/questions/1051668/select-full-word-in-iterm2-using-alt-shift-arrow/1216606#1216606? – Tony Stark Jun 10 '21 at 18:42
  • In an ideal world, I would love to have this directly integrated with the command line, so it also works with integrated terminals like the one in VSCode. ITerm2 seems interesting, I'll look into it, thanks. – yawn Jun 10 '21 at 19:17
  • 1
    Related question at https://superuser.com/questions/444393/how-can-i-select-text-in-the-mac-os-x-terminal-without-a-mouse-for-copy-and-pas – Andrew D. Bond Mar 01 '23 at 06:57

3 Answers3

3

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.
moi
  • 467
  • 4
  • 19
1

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

Jonathan
  • 1,955
  • 5
  • 30
  • 50
  • Apologies, this question was about text selection - does this answer help with selection? (If instead this answer is more about moving the cursor or going to previous commands, this question links to a previous open question where this answer may fit better.) – Andrew D. Bond Mar 01 '23 at 06:44
1

You can't, I've beed looking for long time. This is why people use iTerm they have more flexibility with keyboard only.

https://iterm2.com/features.html

Copy Mode

Use the keyboard to make and modify selections.

enter image description here

flakerimi
  • 2,580
  • 3
  • 29
  • 49