【问题标题】:strange characters when pasting into terminal/fish shell: [200~ and [201~粘贴到终端/鱼壳时出现奇怪的字符:[200~ 和 [201~
【发布时间】:2020-03-18 09:14:05
【问题描述】:

当我使用 Ctrl+Shift+V 将某些内容粘贴到 ranger 时,我得到了奇怪的字符。在这里,我将“粘贴”一词粘贴到游侠中:

一开始我有[200~,最后是[201~。我不知道可能是什么问题(游侠?鱼壳?终端?一些配置文件?)。 粘贴时如何去掉不需要的字符?

更多信息: 我用鱼壳。仅当我使用键盘快捷键 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)。

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

  • Linux Manjaro 19.0.2 XFCE
  • Xfce4 终端 0.8.9.1
  • 鱼3.1.0
  • 游侠 1.9.2(使用 python 3.6.9)

【问题讨论】:

  • 200 和 201 栅栏是“括号粘贴模式”的结果。 cirw.in/blog/bracketed-paste 抱歉,如果它不是一个完整的答案,但它可能会为您的搜索提供正确的方向。

标签: linux terminal copy-paste fish


【解决方案1】:

确实是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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多