Command Delete in Iterm2

I have been working with iTerm2 for a while now and one thing that had frustrated me was figuring out how to map backwards delete word to command delete (and also alt/option delete). I finally figured out a work around and decided I would put up my solution incase anyone else is going through similar issues.

I’m used to Linux terminals where you can use alt-f/alt-b/alt-d/alt-delete for forward-word/back-word/forward-word-delete/backwards-word-delete respectively along with similar keyboard short cuts. I wanted that same functionality on my mac keyboard through iTerm2.

Luckily iTerm2 makes this easy for most mappings. Just navigate to Preferences -> Keys and under the Global Shortcut Keys you can hit the + icon to add your own custom mappings. For most of these I just send escape sequences. For example you can press “⌘ f” then set the Action to Send Escape Sequence and put an “f” in the text box below. This will now let you jump forward by word:

You can use that process to set up most of the common Linux keyboard short cuts, however, once I got to “⌘ delete” that method no longer works. This lead me to searching around for an alternative. I found a promising post here that states you can accomplish this by using the Send Hex Code Action. After following directions, I couldn’t get that to work. That led me to looking up the actual hex codes that various Linux key commands send. You can check those out here. Using the escape code hex “1B” and the delete key hex “8” I was able to gain the functionality that I was looking for:

I should also note that in the post mentioned above the hex number 17 works for the author but didn’t do the trick for me. I am currently using iTerm2 Build 2.1.4, which is working great for me, check the app out here if you haven’t already. Hope this was helpful.