With iTerm2 on Mac, how to delete forward a word from cursor on command-line?

16,358

Solution 1

I don't have a mac handy, but ESC d should in theory do the same thing that ALT-d does.

NOTE: this means hitting ESC, releasing it, then hitting d. Look ma, no key chords.

Solution 2

PreferencesProfileKeys add the following shortcuts:


Send Escape Sequence Esc+ b

Send Escape Sequence Esc+ f

Send Escape Sequence Esc+ [H

Send Escape Sequence Esc+ [F

←Delete Send Hex Code 0x18 0x7f (add bindkey "^X\\x7f" backward-kill-line to .zshrc if you use zShell)

←Delete Send Hex Code 0x1B 0x08

Del→ Send Hex Code 0x0b

Del→ Send Escape Sequence d

Solution 3

Just to add to Alexsander's answer the easiest way to replicate this behaviour is to select the option "Left option key acts as +Esc" in the Preferences->Profiles-> Keys screen.

Solution 4

You can add a shortcut for it, go to "Preferences" → "Profiles" → "Keys", and then click on "+" to add a custom shortcut, and add this:

enter image description here

Now you should be able to delete a word forward by clicking + d.

Solution 5

You can follow this article to set up the key binding in iterm2. It works for me. The hex codes for...
Deleting a word: 0x17.
Deleting a line: 0x15.

enter image description here

Share:
16,358
qazwsx
Author by

qazwsx

Updated on June 02, 2022

Comments

  • qazwsx
    qazwsx about 2 years

    With iTerm2 1.0.0 on Mac OS X 10.6.8, I'd like to delete from cursor to the next end of word, i.e. deleting one word forward. I tried Alt+d but this types the delta operator symbol and doesn't delete. How to suppress the typing but let it delete?

  • chepner
    chepner almost 12 years
    Correct; ESC typically acts as the meta key in Mac OS X, since the Alt key (Option) is used for other purposes.
  • qazwsx
    qazwsx over 8 years
    Where to see a complete list of such key combinations for editing at command line?
  • FacePalm
    FacePalm almost 8 years
    ⌥←Delete : Send Hex Code 0x1B 0x08 to delete a word backwards till spl. character. ( self notes )
  • max pleaner
    max pleaner over 4 years
    This is forward delete a character, the question is about deleting a word
  • kumetix
    kumetix over 4 years
    meh. it works but it ain't so very comfortable on new machines where the ESC is a on the touch bar. seems like manually mapping this to Alt-d is the better choice.