2

I am trying to bind a shortcut to perform cut command in iTerm2. Obviously, cut is bound to Cmd + x, but I would also like it to be bound to Ctrl + w.

I did this easily for paste by going to iTerm2 → Preferences → Profiles → keys and setting the action to paste.

But there is no cut action.

So how can I achieve this?

For some other actions which don't appear listed, I have used their escape code or hex code representation as shown in answers to the question iTerm - going one word backwards and forwards.

I wonder where can I find a list of these representations and their actions?

Ideally, I would like to have Ctrl + w cut the selected text, or if there is no selection, then the entire line. Is this possible?

My goal is to make iTerm2 work more like Emacs.

1
  • It sounds as though the "cut" functionality you're trying to achieve isn't the same as the default Cut action in iTerm2. (For instance, try entering and selecting some text, and notice that the Cut action in the Edit menu is grayed out.) If you simply want to remap the shortcut for the default Cut action, go to System Preferences > Keyboard > Shortcuts > App Shortcuts (on the left), click the + button, enter the Cut menu title and press Control-W for the keyboard shortcut, and click Add.
    – aaplmath
    Jul 31, 2018 at 18:28

1 Answer 1

1

The escape sequences mentioned in that question correspond to zle (zshell line editor) widgets documented here.

They provide emacs(or vi) like editing functions. You can see which are currently bound to keys by typing bindkey command in zsh.

You can also write shell functions and then declare those as widgets which can then be key bound. Here is a guide to zle.

The slight complication is that Iterm2 will not, by default, pass alt or Cmd modified strokes through to the shell.

This can be configured in iTerm2 → Preferences → Profiles → keys.

An alt+ key is equivalent to esc followed by key, hence to pass this to the sh you add a key bind to:

Action: Send escape sequence

Esc+: key

You must log in to answer this question.

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