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

iTerm2 Build 3.4.19粘贴时自动添加多余转义斜杠求助

iTerm2 3.4.19粘贴含特殊字符字符串自动添加转义斜杠的解决方法

问题场景

当在iTerm2 Build 3.4.19的CLI中粘贴含特殊字符的字符串(比如带?、&的URL)时,所有特殊字符会被自动添加转义斜杠。示例:

原链接:

https://accounts.spotify.com/authorize?client_id=xxxxx&response_type=code&redirect_uri=http://localhost:3000&scope=playlist-read-private

粘贴后变为:

https://accounts.spotify.com/authorize\?client_id\=xxxxx\&response_type\=code\&redirect_uri\=http://localhost:3000\&scope\=playlist-read-private

已尝试关闭「Escape shell characters with \」选项、执行printf '\e[?2004h'、关闭「Terminal may enable paste bracketing」设置,但均无效,MacOS原生Terminal无此问题。

可能原因及解决方法

1. 检查shell的自动转义配置

如果使用zsh,可能是shell自身或插件的粘贴转义机制在起作用:

  • 执行echo $ZSH_VERSION确认当前shell,打开~/.zshrc检查是否启用了bracketed-paste插件,若有则移除该插件,重启iTerm2。
  • 执行bindkey | grep paste查看粘贴相关绑定,若存在自动转义的绑定,可通过bindkey -r '^[[200~'解除。

2. 排查iTerm2的深层设置

  • 打开iTerm2偏好设置 →「Profiles」→ 选中当前配置 →「Advanced」:
    • 取消勾选「Treat pasted URLs as single tokens」(若存在)
    • 关闭「Escape non-printable characters」选项
  • 进入「Profiles」→「Text」,确认「Smart Selection」的规则未对URL做额外转义处理。

3. 重置iTerm2配置

若上述方法无效,可能是配置文件损坏:

  • 关闭iTerm2,执行以下命令备份并重置配置:
    mv ~/Library/Preferences/com.googlecode.iterm2.plist ~/Library/Preferences/com.googlecode.iterm2.plist.backup
    
    重启iTerm2后测试粘贴功能。

4. 检查第三方shell框架或自定义脚本

如果使用oh-my-zsh、prezto等框架,或自定义了~/.zshrc、~/.bashrc等脚本,检查是否有代码对粘贴内容进行转义处理,比如包含修改粘贴内容的sed、awk逻辑或自定义函数,找到后注释或删除相关代码。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 00:10:28