Pi 的配置、擴充、平台設定和 API 參考。

終端設定

Pi 使用 Kitty keyboard protocol 進行可靠的修飾鍵檢測。大多數現代終端都支援此協議,但有些需要配置。

基蒂,iTerm2

開箱即用。

蘋果終端

Pi 在可用時啟用增強的關鍵報告。如果 Terminal.app 仍然發送 Shift+Enter 的普通 Return,則 pi 使用本地 macOS 修飾符後備將該 Return 視為 Shift+Enter

只有當 pi 與 Terminal.app 在同一台 Mac 上運行時,此後備才有效。它無法透過遠端SSH偵測到本機鍵盤。

幽靈般的

新增到您的 Ghostty 配置(macOS 上為 ~/Library/Application Support/com.mitchellh.ghostty/config,Linux 上為 ~/.config/ghostty/config):

keybind = alt+backspace=text:\x1b\x7f

較舊的克勞德程式碼版本可能添加了此 Ghostty 映射:

keybind = shift+enter=text:\n

該映射發送一個原始換行位元組。在 pi 內部,它與 Ctrl+J 無法區分,因此 tmux 和 pi 不再看到真正的 shift+enter 按鍵事件。

如果 Claude Code 2.x 或更新版本是您添加該映射的唯一原因,您可以將其刪除,除非您想在 tmux 中使用 Claude Code,因為它仍然需要 Ghostty 映射。

Pi 將 Ctrl+J 綁定為預設換行符別名,因此 Shift+Enter 透過重新映射繼續在 tmux 中工作,無需額外的 pi 配置。

韋茲術語

WezTerm 通常透過 xterm modifyOtherKeys 開箱即用地運行 Shift+Enter。若要明確使用 Kitty 鍵盤協議,請建立 ~/.wezterm.lua

local wezterm = require 'wezterm'
local config = wezterm.config_builder()
config.enable_kitty_keyboard = true
return config

在 macOS 上,WezTerm 預設將 Option+Enter 綁定到全螢幕。若要使用 Option+Enter 進行 pi 後續佇列,請新增此鍵覆蓋:

local wezterm = require 'wezterm'
local config = wezterm.config_builder()
config.keys = {
  {
    key = 'Enter',
    mods = 'ALT',
    action = wezterm.action.SendString('\x1b[13;3u'),
  },
}
return config

如果您已有一個 config.keys 表,請在其中新增條目。

在 WSL 上,WezTerm 可能需要可見的硬體遊標來定位 IME 候選視窗。如果 CJK IME 候選項不跟隨文字遊標,請在執行 pi 之前設定 PI_HARDWARE_CURSOR=1 或在設定中將 showHardwareCursor 設定為 true

阿拉克里蒂

Alacritty 通常開箱即用,適用於 Shift+Enter。在 macOS 上,Option+Enter 可能以普通的 Enter 形式出現。若要使用 Option+Enter 進行 pi 後續隊列,請加入 ~/.config/alacritty/alacritty.toml

[[keyboard.bindings]]
key = "Enter"
mods = "Alt"
chars = "\u001b[13;3u"

更改配置後重新啟動 Alacritty。

VS Code(整合終端)

VS Code 1.109.5 及更高版本預設在整合終端中啟用 Kitty 鍵盤協議,因此 Shift+Enter 應該可以開箱即用。

早於 1.109.5 的 VS Code 版本需要 Shift+Enter 的明確終端鍵綁定。

keybindings.json地點:

  • 蘋果系統:~/Library/Application Support/Code/User/keybindings.json
  • Linux:~/.config/Code/User/keybindings.json
  • 窗戶:%APPDATA%\\Code\\User\\keybindings.json

加入keybindings.json

{
  "key": "shift+enter",
  "command": "workbench.action.terminal.sendSequence",
  "args": { "text": "\u001b[13;2u" },
  "when": "terminalFocus"
}

Windows 終端

加到settings.json(Ctrl+Shift+,或設定→開啟JSON檔案)以轉送修改後的Enter鍵pi使用:

{
  "actions": [
    {
      "command": { "action": "sendInput", "input": "\u001b[13;2u" },
      "keys": "shift+enter"
    },
    {
      "command": { "action": "sendInput", "input": "\u001b[13;3u" },
      "keys": "alt+enter"
    }
  ]
}
  • Shift+Enter 插入新行。
  • 預設情況下,Windows 終端將 Alt+Enter 綁定到全螢幕。這會阻止 pi 接收 Alt+Enter 進行後續排隊。
  • Alt+Enter 重新映射到 sendInput 會將真正的調和弦轉發到 pi。

如果您已經有一個 actions 數組,請將物件加入其中。如果舊的全螢幕行為仍然存在,請完全關閉並重新開啟 Windows 終端。

xfce4-終端,終結者

這些終端的轉義序列支援有限。修改後的 Enter 鍵(如 Ctrl+EnterShift+Enter)無法與普通的 Enter 區分開來,從而阻止自訂鍵綁定(如 submit: ["ctrl+enter"])工作。

為了獲得最佳體驗,請使用支援 Kitty 鍵盤協定的終端:

IntelliJ IDEA(整合終端)

內建終端對轉義序列的支援有限。 Shift+Enter 無法與 IntelliJ 終端機中的 Enter 區分開。

如果您希望硬體遊標可見,請在執行 pi 之前設定 PI_HARDWARE_CURSOR=1 (預設為停用相容性)。

考慮使用專用的終端模擬器以獲得最佳體驗。