1

I want to level up my terminal skills, specifically when entering commands, to improve my efficiency. For example, when typing a command, I want to delete a word to the left of the cursor, instead of pressing backspace 5 times.

I already know how this works: the terminal app can catch a keyboard shortcut, such as Ctrl-backspace, and send a special keycode to the shell. The shell has built in functionality for this type of editing, and it recognizes the keycode and does what we want. Did I explain it correctly?

shortcut to keycode settings

This works and is fantastic functionality, but where can I find a list of things that are possible? Just today I realized that 0x1f means "undo". I never knew this was possible, and I love it! I want to see what else is possible, but I don't know what to search for! I tried for half an hour and gave up.

I am using Macos, the default Zsh 5.8 shell, and iTerm2 app.

Morgus Lethe
  • 121
  • 3
  • You misunderstood the question, I don't want a list of TERMINAL app functionality, I want a list of SHELL functionality. I need to find a list where it says "0x1f means undo, 0x1b means delete word left, 0x7f means delete character". – Morgus Lethe Jun 20 '21 at 11:55

2 Answers2

4

Those keyboard shortcuts are documented in your shell's manual. Since your shell is zsh, look at the chapter “Zsh Line Editor” in the manual, available locally with man zshzle.

Regarding the correspondence the key bindings involving Control and ESC and keyboard keys, see key bindings table? and How do keyboard input and text output work? for some background. Note in particular that you can press Ctrl+V followed by a key to see what escape sequence it sends. On a Mac terminal, by default, the Option key sends ESC followed by what the key sends (usually).

1

I found the answer, the functionality I am describing is controlled through the command bindkey. Running bindkey without any options will print out the current bindings, here is an example:

"^@" set-mark-command
"^A" beginning-of-line
"^B" backward-char
"^D" delete-char-or-list
"^E" end-of-line
"^F" forward-char
"^G" send-break
"^H" backward-delete-char
"^I" expand-or-complete
"^J" accept-line
"^K" kill-line
...

Because I didn't know these are called "key bindings" I couldn't find the answer on google.

So now I have a list of what is possible, I just need to translate it to hex to make the answer truly useful to someone using iTerm2.

Morgus Lethe
  • 121
  • 3
  • I presume that you know that ^A (control-A ) is hex 0x01, ^B is 0x02, and so on? Also that the tty driver will respond to certain keys before sending them to the shell - so run stty -a to see those settings. – Graham Nicholls Jun 21 '21 at 18:54