69

I am using iTerm as a terminal in my mac. I am not able to delete a word in command line for ex in command cd /path/to/dir, i want to delete just path word , then how can i do that in iTerm.

basically what is the shortcut to delete a word in iTerm.

I looked at https://apple.stackexchange.com/questions/154292/iterm-going-one-word-backwards-and-forwards and fn+option+delete is just deleting a single character, not the whole word.

Community
  • 1
  • 1
Rohit
  • 761
  • 1
  • 6
  • 8

4 Answers4

148

Go to your iTerm preferences select "Profiles" then "Key" and change your presets in "Natural Text Editing"

iTerm Preferences

It should work immediately after.

It works with iTerm version 3.3.12

Edit:

In version 3.4, there's a slight UI change. So you need to go specifically to your iTerm preferences select Profiles > Keys > Key Mappings > Presets > Natural Text Editing

enter image description here

KillianGDK
  • 1,922
  • 1
  • 8
  • 9
54

This helped me.

Delete a word - Send Hex Codes - 0x1b 0x08 or 0x17

Delete a line - Send Hex Codes - 0x15

iTerm2 delete a word shortcut

Community
  • 1
  • 1
Vignesh Raja
  • 7,927
  • 1
  • 33
  • 42
  • I have the same keybinding for `emacs` as well but when I set on `iTerm` it is not detected from `emacs`. Is it possible to use it only on terminal/bash usage and disable if `emacs` is on? – alper Mar 13 '20 at 11:47
  • 1
    Perfect! Thank you. – Amit Yadav Sep 02 '21 at 07:21
  • In Monterey I had some trouble due to some common options not showing. This was what worked for me. Thanks! – mike dangelo Apr 11 '22 at 20:46
28

ctrl + w in iTerm,

BTW, in text editors
alt + delete to delete whole previous word
fn + delete to delete next word

Kiryl Plyashkevich
  • 2,157
  • 19
  • 18
8

esc+d should work as a default.

Or you can add a Send Escape Sequence based keyboard mapping for esc-d:

enter image description here

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • 4
    This solution didn't work on my end, `ctrl + w` is the keyboard maaping in iTerm, but i cound't find its `send escape sequence` – alper Mar 13 '20 at 13:40