Search code examples
linuxterminalcopy-pastefish

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


When I paste something into ranger with Ctrl+Shift+V I get strange characters. Here I pasted word "paste" into ranger:

enter image description here

And on the begining I have [200~ and at the end [201~. I have no idea what could be the problem (ranger? fish shell? terminal? some config files?). How to get rid of unwanted characters while pasting?

Some more info: I use fish shell. Problem only persists when I start ranger with keyboard shortcut Ctrl+O. It works fine when I start ranger by manually entering commands ranger or ranger_cd or just by pasting text directly into fish shell (without starting ranger at all). Ctrl+O shortcut is defined by:

function fish_user_key_bindings
    bind \co ranger_cd
end

My ranger_cd is function:

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

(its purpose is to save last dir chosen in ranger and cd into it after exiting ranger)

I also noticed that Ctrl+V doesn't work in ranger (it pastes only ^V), but it works properly directly in fish shell (it pastes what I copied earlier, just as Ctrl+Shift+V).

Any ideas what could be wrong? Thank you in advance. I use:

  • Linux Manjaro 19.0.2 XFCE
  • Xfce4 terminal 0.8.9.1
  • fish 3.1.0
  • ranger 1.9.2 (with python 3.6.9)

Solution

  • That's bracketed paste mode indeed.

    Fish enables it mainly to not execute multi-line pastes immediately. It disables it when you execute a command via the commandline and reenables it when you gain control again.

    It's not typical to start interactive things via bindings, so fish doesn't disable it there.

    To disable it manually, use __fish_disable_bracketed_paste and __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