粘贴到 terminal/fish shell 时的奇怪字符:[200~ 和 [201~

strange characters when pasting into terminal/fish shell: [200~ and [201~

当我使用 Ctrl+Shift+V 将内容粘贴到 ranger 时,我得到了奇怪的字符。在这里,我将单词 "paste" 粘贴到 ranger:

开头有 [200~,结尾有 [201~。我不知道可能是什么问题(护林员?fish shell?终端?一些配置文件?)。 如何去掉粘贴时不需要的字符?

更多信息: 我用鱼shell。只有当我使用键盘快捷键 Ctrl+O 启动 ranger 时,问题才会持续存在。当我通过手动输入命令 rangerranger_cd 或直接将文本粘贴到 fish shell 中(根本不启动 ranger)来启动 ranger 时,它工作正常。 Ctrl+O 快捷方式定义为:

function fish_user_key_bindings
    bind \co ranger_cd
end

我的ranger_cd是函数:

function ranger_cd
    set -l tempfile '/tmp/chosendir'

    ranger --choosedir $tempfile (pwd)
    if [ -f "$tempfile" ]; and [ (cat -- $tempfile) != (echo -n (pwd)) ]
        cd (cat $tempfile)
    end
    rm -f -- $tempfile
end

(目的是保存ranger最后选择的目录,退出ranger后cd进去)

我还注意到 Ctrl+V 在 ranger 中不起作用(它只粘贴 ^V),但它直接在 fish 中正常工作 shell(它粘贴了我之前复制的内容,就像Ctrl+Shift+V)。

有什么想法是错误的吗?先感谢您。我使用:

确实是bracketed paste mode

Fish主要是让它不立即执行多行粘贴。它会在您通过命令行执行命令时禁用它,并在您再次获得控制权时重新启用它。

通过绑定启动交互式事物并不常见,因此 fish 不会在那里禁用它。

要手动禁用它,请使用 __fish_disable_bracketed_paste__fish_enable_bracketed_paste:

function ranger_cd
    set -l tempfile '/tmp/chosendir'

    __fish_disable_bracketed_paste
    ranger --choosedir $tempfile (pwd)
    __fish_enable_bracketed_paste
    if [ -f "$tempfile" ]; and [ (cat -- $tempfile) != (echo -n (pwd)) ]
        cd (cat $tempfile)
    end
    rm -f -- $tempfile
end

如果其他人正在搜索这个并且没有使用 fish shell,我刚刚意识到如果我不小心尝试使用 Ctrl-V 粘贴到终端它不起作用然后记得粘贴使用 Ctrl-Shift-V 然后下一个粘贴将有 ^[[200~ 开始,~ 结束。如果我只用 Ctrl-Shift-V 粘贴,它就可以正常工作。