iTerm2: delete line?

I got it. I have no idea why Hex Code mappings in iTerm2 produce the associated Ctrl+key mappings, but they do. No idea what 0x00 means, either, as it's not assigned to A as might be expected. (though I do believe Unix has its own conventions relating to treating null bytes -- we have e.g. xargs accepting a null byte delimiting format from find for example -- It would be neat if we can bind this to a hotkey with iTerm2)

I was able to find that Ctrl+U does nearly the exact task I want (it deletes the entire line rather than deleting only what is before cursor, but whatever... Ctrl+Y as a bonus can bring it all back). Then I curiously saw that I had hex codes 0x1 and 0x5 mapped to ^A and ^E respectively, for my Cmd+Left and Cmd+Right... so 0x15 is for ^U!


For Mac OS, most editor share the common shortcut + Delete: delete to start of the line, in iTerm2 we can switch to this key configuration

enter image description here


Mapping hex code 0x15 to + ←Delete in most shells deletes the entire line (content to the left and right of the cursor). While sometimes not as compatible, I find that mapping:

+←Delete to Send Hex Codes:

0x18 0x7f

performs the desired functionality. If you're running ZSH, you'll likely also need to add this to your .zshrc file:

$ echo 'bindkey "^X\\x7f" backward-kill-line' >> ~/.zshrc

as by default ZSH doesn't map backward-kill-line to anything.

Furthermore, you can also delete everything to the right of your cursor by mapping:

+fn+←Delete or +Delete→ to Send Hex Codes:

0x0b

I wrote a comprehensive guide to adding most of OSX's standard keybinding to your terminal here