0

I'm very surprised that this functionality or even information about it is so hard to find. With the default terminal (in December 2023), the usual editor key combinations like option-backspace to delete a word, or command-backspace to delete a whole line, or command-left and command-right keys to move to the beginning and end of the line respectively, do not work. I don't know the reasons why they don't work, and I can't think of reasons why they can't be made to work. Is there a setting in the terminal to make them work? Or is there a terminal that does this out-of-the-box?

Before you tell me, yes I do know there are other key combinations in the default terminal: ctrl-a to go to beginning of line, ctrl-w to delete a word backward, ctrl-u to delete a whole line backward, ctrl-e to go to end of the line, and a bunch of others that I can remember. But there are two problems: I constantly switch between my text editor (VSCode) and terminal and it's really annoying to have to use two distinct key combinations (because it breaks my line of thought all the time), and the ctrl-* key combos are awkward AF to use because there's only one ctrl key on a Macbook and they can't be used with one hand unless you want RSI and arthritis for Christmas.

Now, I have surveyed some terminals but none of them does what I want. iTerm2 behaves exactly like the default terminal and I don't know what all the rave is about (it seems to have the same features too). There's also Hyper, Alacritty, Kitty, and Rio, but in all of them (as far as I remember), option-backspace works but cmd-backspace doesn't. Warp is the only one that does what I want (and much much more), but it only support some Unix shells and doesn't support Powershell or Xonsh. Why oh why is it so hard to find a terminal that just behaves like a text editor??? Surely (1) that should be easy and (2) that should just, like, make sense? The same key combos that work everywhere else doesn't work in the terminal and only in the terminal??? Really???

EDIT

As an example, Windows Terminal behaves like a text editor and it even has the bonus that the escape key clears the current line, but sadly it only support Windows. If there's something like the Windows Terminal for Mac that would be amazing.

EDIT EDIT

For context, I'm using Powershell (Core) 7.4.0, just to be clear. I'm under the expression that this is to do with the terminal, but people pointed out in the comments that it might be to do with the shell instead, so I'm telling you here that the shell is Powershell 7.4.0. Although, I'd like everything to work with Xonsh as well ideally.

0

1 Answer 1

1

I'm honestly astonished that I'm having to answer my own question here. Is no Mac user in the world ever bothered by this??? Anyway here goes.

Some of the comments of the question claim that it's "not the responsibility of the terminal", but technically speaking they're wrong. It can be the responsibility of the terminal, and that's my point. It can also be the responsibility of the shell, for example PSReadLine for Powershell, but unfortunately Powershell doesn't seem to recognise the "command" key on a Mac. So here's a solution, using iTerm2. Note that in this case, the terminal is responsible for the solution.

Use iTerm2. iTerm2 doesn't do this by default, but it has options to assign key chords (combos). Go to settings -> profiles -> <select profile for example "default"> -> keys -> key mappings (or settings -> keys -> key bindings if you want to set it globally, not recommended), and you'll see a list of default key bindings. You can add your own with the "+" sign at the bottom-left. Press that button, press your key combo, and in the "action" drop-down menu, select "send hex code", which is under the section "send keystrokes" (you'll need to scroll down a bit). The delete-word, delete-line, move-to-beginning-of-line, and many more actions are encoded in hex codes. Now, I don't know the full list, but luckily I found exactly what I need:

  • 0x17 for deleting a word.
  • 0x15 for deleting a line.
  • 0x01 for moving to the beginning of line.
  • 0x05 for moving to the end of line.

So for me, I've set command-backspace to 0x15, option-backspace to 0x17, command-left remapped to 0x01 (command-left already has a default action that I overwrote), and command-right remapped to 0x05.

In addition, I want to make option-left and option-right skip words just like in a text editor. For this, we need to use escape sequences and not hex codes, which are also under the section "send keystrokes". Skip word left is escape-b, and skip word right is escape-f.

This makes iTerm2 behave mostly like a text editor, like it should always have been from the outset in my opinion. Furthermore in my case, I've also set the escape key to 0x05 0x15 (delete line regardless of where the cursor is), to match the behaviour of Powershell in Windows Terminal, but I don't entirely recommend this for everyone because I think, but I'm not sure, that escape key is used for escape sequences or something in terminals (but I never use them so whatever).

EDIT

This guy actually describes exactly what I found out by trial and error. I wish he saw my question here first.

1
  • Most Mac users probably are just relying on the Emacs-inspired keybindings which work basically everywhere (including shells, dialog boxes and a lot of applications). But glad to see that you managed to solve your problem and left documentation for others.
    – nohillside
    Dec 22, 2023 at 18:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .