Word/Line deletion and navigation shortcuts in iTerm2
In OSX, ⌥+⌫ and ⌘+⌫ are the shortcuts for deleting a word and deleting a line respectively. ⌘+ ← and ⌘+ → are for going to the beginning and end of lines. By default, iTerm2 isn't configured this way, and there are a lot of misleading guides online. The following is what I've found to work on my machine.
- Open the preferences (⌘+,) and go to the Keys tab.
- Add a global shortcut key, and just type in your shortcut
- In the Action dropdown, select Send Hex Code
The hex codes for...
- Deleting a word: 0x17.
- Deleting a line: 0x15.
- Moving to the beginning of the line: 0x01.
- Moving to the end of the line: 0x05.
Just open a new tab, and it should work!
Here is a screenshot, for clarity.
Sources:
http://stackoverflow.com/questions/15733312/iterm2-delete-line
Steven Lu for deleting a line
Carlos for deleting a word
http://apple.stackexchange.com/questions/89981/remapping-keys-in-iterm2
` for navigating lines
EDIT: I've added code for beginning and end lines, and i'm currently working on turning this into a nice, complete list.
Related protips:
Use ⌥ ← and ⌥→ to jump forwards / backwards words in iTerm 2, on OS X
Written by Levi Tan Ong
Related protips
7 Responses

Thanks! It was helpful!
great tip.

Any ideas how to delete line forward and delete word forward?

I found a useful post in stackexchange, and I'll integrate some of that information into this protip (with references of course) http://apple.stackexchange.com/questions/89981/remapping-keys-in-iterm2
In short, instead of selecting "Send Hex Codes", select "Send Escape Sequence", and just type "d".

deleting a word should actually be hex code 0x1B 0x08
this will delete up to punctuation.

Alternatively, this exists initially:
Ctrl+a = move to the begging of the line
Ctrl+e = move to the end of the line

Amazing! I did not know this before you brought it up.