You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iTerm2:如何为下拉菜单外的操作设置自定义快捷键?

Customizing Word-Deletion Shortcuts in iTerm2 with Hex Codes

Great question! When you want to replace iTerm2's default word-deletion shortcuts (and the Action menu doesn't list the exact "delete previous/next word" options directly), using hex codes tied to standard terminal control sequences is the way to go. Let's walk through how to find these codes and set them up.

Finding the Right Hex Codes for Your Actions

First, these word-deletion actions rely on standard terminal control sequences that most shells (like bash/zsh) recognize. You can either use the pre-known codes below, or find any sequence yourself using a simple terminal trick:

1. Pre-Known Hex Codes for Word Deletion

Here are the exact codes you need for your two desired actions:

  • Delete cursor previous word: Two common sequences work here:
    • 0x17 (corresponds to the standard Ctrl+W shortcut, which most shells use to delete the word before the cursor)
    • 0x1b 0x7f (corresponds to Alt+Backspace, another widely used shortcut for this action)
  • Delete cursor next word:
    • 0x1b 0x64 (corresponds to Alt+D, the standard shortcut for deleting the word after the cursor)

2. How to Look Up Any Shortcut's Hex Code

If you ever need to find the hex code for another terminal action, use the cat -v command:

  1. Open your terminal and run cat -v
  2. Press the shortcut you want to investigate (e.g., the default Alt+D for deleting the next word)
  3. You'll see a human-readable escape sequence (like ^[d for Alt+D)
  4. Convert this sequence to hex:
    • ^[ is the ESC character, which is 0x1b
    • Regular letters (like d) use their ASCII hex value (0x64 for 'd')
    • Control characters (like ^W) are calculated by subtracting 64 from the ASCII value of the uppercase letter: W is ASCII 87, so 87-64=23, which is 0x17

Setting Up the Custom Shortcuts in iTerm2

Once you have the hex codes, here's how to map them to your preferred shortcuts:

  1. Open iTerm2 → go to Preferences → Keys
  2. Click the + button at the bottom to add a new shortcut
  3. Press your desired custom shortcut (e.g., Ctrl+Option+Backspace for deleting the previous word)
  4. From the Action dropdown menu, select Send Hex Code
  5. Paste the corresponding hex code into the input field (e.g., 0x17 for the previous word)
  6. Click OK to save the mapping
  7. Repeat the process for the "delete next word" action with its hex code (0x1b 0x64)

Are There Official Hex-Action Mappings?

iTerm2 doesn't have a dedicated public mapping table for these codes because they follow standard ANSI/POSIX terminal control sequences. Most common line-editing actions use sequences that are universally recognized by shells like bash, zsh, and fish. The cat -v method above is the most reliable way to look up any sequence you need.

内容的提问来源于stack exchange,提问作者samthegolden

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:00:59