Open austinarbor opened 6 years ago
Looks like an issue with bracketed-paste-magic. I'll look into it but for now, you could try one of these:
A little more info: It looks like this was not an issue with zsh version 5.4.2, but is an issue with 5.5.1.
I do have this in my misc.zsh
so I think bracketed pasted magic is disabled for me?
#autoload -Uz bracketed-paste-magic
#zle -N bracketed-paste bracketed-paste-magic
Regarding https://github.com/zsh-users/zsh-autosuggestions/issues/238#issuecomment-389324292, in which file should I put those methods?
I think bracketed pasted magic is disabled for me?
Ok I am able to reproduce it with bracketed-paste-magic, but not without, so I suspect you may still somehow have it enabled.
What do you get when you run echo $functions[bracketed-paste-magic]
?
You may also try running zsh -f
and sourcing this plugin manually to see if it is caused by something else in your zshrc. If that's the case you can systematically comment out things from your zshrc until the problem goes away to determine what line is causing the issue.
Regarding #238 (comment), in which file should I put those methods?
You can put them in your .zshrc
or in any of the files loaded by your .zshrc
, but they will only make a difference if you are using bracketed-paste-magic.
Ah, it appears overriding . Confirming disabling misc.zsh
in $ZSH_CUSTOM
directory is not workingbracketed-paste-magic
does resolve the issue. https://github.com/zsh-users/zsh-autosuggestions/issues/238#issuecomment-389324292 did speed up pasting, but did not resolve the issue.
Edit: I didn't have misc.zsh
in $ZSH_CUSTOM/lib/misc.zsh`
I've reproduced something very similar to this (not yet sure if it deserves a new issue). I also do not have bracketed-paste-magic
. echo $functions[bracketed-paste-magic]
yields nothing.
For me, I don't need to press the right key to make the double suggestion appear. eg, in this sequence:
ls
, and the suggestion ls -altr
appears. .zsh_history
and the result is ls .zsh_history-altr
. ls .zsh_history
, so the appended suggestion is harmless, just confusing.The exact line that is causing the issue is this one. Commenting out that line (or reverting to the commit before) makes everything work perfectly.
zsh-autosuggestions: rev: 42f5a06f7f29007d91e37f85e1dc5a80f1b7c059 zsh: zsh 5.1.1 (x86_64-ubuntu-linux-gnu) zplug: 2.4.2
I can also confirm that disabling bracketed-paste-magic fixed the problem with pasting.
@hlascelles Can you reproduce using zsh -f
and sourcing the plugin manually?
@hlascelles You are absolutely correct =] Cheers mate!
@hlascelles Thanks this does fix properly the suggestion being appended. The solution described in https://github.com/zsh-users/zsh-autosuggestions/issues/238#issuecomment-389324292 do not work completely when the paste do not happen on the start : e.g.
git clone
git@github.com:qos-ch/slf4j.git
git clone git@github.com:qos-ch/slf4j.git
git clone
(where the cursor is), e.g. git@github.com:zsh-users/zsh-autosuggestions.git
git clone git@github.com:zsh-users/zsh-autosuggestions.git
The pasted string is inverted.
git clone git@github.com:zsh-users/zsh-autosuggestions.git
becomes
git clone git@github.com:zsh-users/zsh-autosuggestions.gitgit@github.com:qos-ch/slf4j.git
@hlascelles Can you reproduce using
zsh -f
and sourcing the plugin manually?
@ericfreese yes:
$ zsh -f
host% autoload -Uz bracketed-paste-magic
host% zle -N bracketed-paste bracketed-paste-magic
host% source zsh-autosuggestions.zsh
host% source <paste anything here, then press left arrow>
Thank you for the simple steps @aaronjensen!
Yes, @ericfreese I can replicate the problem doing sourcing the plugin manually as per the steps above.
@aaronjensen @hlascelles I'm a little confused here. @hlascelles's comment said that he had bracketed-paste-magic disabled, but @aaronjensen's zsh -f
repro steps have it enabled. I'm also assuming @aaronjensen meant the right arrow instead of left? These seem to be repro steps for the original issue (with bpm enabled).
@hlascelles Are you able to reproduce the issue you posted about using zsh -f
?
@hlascelles Are you able to reproduce the issue you posted about using
zsh -f
?
@ericfreese I've had this issue too, and I'm able reproduce this problem using zsh -f
following @aaronjensen's steps.
If I comment out bpm in lib/misc.zsh
or preferably, my own at $ZSH_CUSTOM/lib/misc.zsh
, the issue goes away.
@aaronjensen @hlascelles I'm a little confused here. @hlascelles's comment said that he had bracketed-paste-magic disabled, but @aaronjensen's
zsh -f
repro steps have it enabled
You are correct, sorry I didn't read the thread closely enough. My repro steps are for the originally reported issue. I don't know how to repro it w/o bpm.
I'm also assuming @aaronjensen meant the right arrow instead of left?
I meant left, as that triggers displaying the suggestion (but not filling it). Right is problematic too as that fills the suggestion.
Ok, that makes sense. Lets keep this thread about the bracketed-paste-magic issue and if there is another issue that we can recreate without bracketed-paste-magic, lets open a new issue for it.
There is a very easy workaround for this issue which is to add bracketed-paste
to the list of widgets that clear the suggestion. I've added a spec to the test suite to demonstrate the workaround: https://github.com/zsh-users/zsh-autosuggestions/commit/ce6ee94f30abeaa63cfd5d3c861175e15045f615
Because there's such an easy workaround for this, it'll be pretty low priority for me, but if someone wants to put up a PR that fixes it and doesn't break anything else I'll be happy to merge.
This seems to work for me, thanks. I thought I had tried this before, but it all seems to be working as I'd hope, so far. Here's my full setup:
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
# https://github.com/zsh-users/zsh-autosuggestions/issues/351
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
Maybe this will help someone.
I was using the code just above and was getting unused suggestions showing in the terminal buffer after executing a command - zsh-autosuggestions 0.6.3, macOS, iTerm.
I added accept-line
to ZSH_AUTOSUGGEST_CLEAR_WIDGETS
and it fixed the issue.
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste accept-line)
Example (italic text for gray suggestions. | for cursor position)
% git status --porcelain % git status| --porcelain [hit enter] % git status --porcelain [buffer displays this] [output for git status only]
Flag --porcelain is showing in buffer with white text as if it was executed, but only git status was executed.
Can confirm I have this issue and I have bracketed-paste-magic
present as well. Like @ericfreese and others mentioned, the fix is to add ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste accept-line)
to your ~/.zshrc
file.
I used to have both the slow-paste issue and the wrong autocompletion after paste. I used to solve it with similar code to https://github.com/zsh-users/zsh-autosuggestions/issues/351#issuecomment-483938570 before I decided to have a look into oh-my-zsh.
I found this: https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/misc.zsh#L4-L16
... which sets up everything we want to undo.
So setting DISABLE_MAGIC_FUNCTIONS=true
before sourcing oh-my-zsh does the trick in a much simpler way. It also skips url-quote-magic
which I don't care about.
@levito that's the nuclear option as it disables those things entirely. The above only disables it when it matters and still lets you use them. If you don't want them though, by all means use that approach. If you want bracketed paste magic and url quote magic, then the original comment will work.
This seems to work for me, thanks. I thought I had tried this before, but it all seems to be working as I'd hope, so far. Here's my full setup:
# This speeds up pasting w/ autosuggest # https://github.com/zsh-users/zsh-autosuggestions/issues/238 pasteinit() { OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]} zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`? } pastefinish() { zle -N self-insert $OLD_SELF_INSERT } zstyle :bracketed-paste-magic paste-init pasteinit zstyle :bracketed-paste-magic paste-finish pastefinish # https://github.com/zsh-users/zsh-autosuggestions/issues/351 ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
This workaround works perfect!!!
# This speeds up pasting w/ autosuggest # https://github.com/zsh-users/zsh-autosuggestions/issues/238 pasteinit() { OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]} zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`? } pastefinish() { zle -N self-insert $OLD_SELF_INSERT } zstyle :bracketed-paste-magic paste-init pasteinit zstyle :bracketed-paste-magic paste-finish pastefinish # https://github.com/zsh-users/zsh-autosuggestions/issues/351 ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
This breaks the rare case that we want to see the suggestions for the pasted content. Otherwise, seems to work well!
PS: I already had accept-line
in ZSH_AUTOSUGGEST_CLEAR_WIDGETS
.
adding ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
works only if ZSH_AUTOSUGGEST_STRATEGY
equals to history
, but if i add completion
suggestion is still not cleared
upd: nvm, seems problem was also in ohmyzsh magic functions turned on by default, when i added DISABLE_MAGIC_FUNCTIONS="true" to .zshrc suggestions started being cleared properly
@ericfreese the workaround in https://github.com/zsh-users/zsh-autosuggestions/issues/351#issuecomment-572068804 introduces incorrect history navigation using up/down keys seemingly because it's not possible to append to ZSH_AUTOSUGGEST_CLEAR_WIDGETS
?
I see that accept-line
is already present here. Is it expected that you can only replace the value of this variable and not append to it? If that's the case, is there a plan to add bracketed-paste
also in here?
Currently, my workaround involves copy pasting the entire list from config.zsh
and adding bracketed-paste
to the end like so:
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(
history-search-forward
history-search-backward
history-beginning-search-forward
history-beginning-search-backward
history-substring-search-up
history-substring-search-down
up-line-or-beginning-search
down-line-or-beginning-search
up-line-or-history
down-line-or-history
accept-line
copy-earlier-word
bracketed-paste
)
which seems to sort everything out.
Will @sangeeth96 fix be implemented in the package ? Or is this something for zsh to fix ?
This seems like an easy fix but the issue has been open for more than 3 years.
@sangeeth96 Unfortunately, your workaround does not work when ZSH_AUTOSUGGEST_STRATEGY=(completion history)
. It seems to work only when ZSH_AUTOSUGGEST_STRATEGY=(history)
For the time being. I have set DISABLE_MAGIC_FUNCTIONS=true
in ~/.zshrc
. Not sure what all it disables.
This seems to work for me, thanks. I thought I had tried this before, but it all seems to be working as I'd hope, so far. Here's my full setup:
# This speeds up pasting w/ autosuggest # https://github.com/zsh-users/zsh-autosuggestions/issues/238 pasteinit() { OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]} zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`? } pastefinish() { zle -N self-insert $OLD_SELF_INSERT } zstyle :bracketed-paste-magic paste-init pasteinit zstyle :bracketed-paste-magic paste-finish pastefinish # https://github.com/zsh-users/zsh-autosuggestions/issues/351 ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
This works for me even when I have ZSH_AUTOSUGGEST_STRATEGY=(completion history)
Thanks :)
The workaround works for me when using Ctrl+Shift+v for pasting.
But sometimes muscle memory takes over when switching between other programs and the terminal, and I accidentally use Ctrl+v. When I then notice my mistake and use Ctrl+Shift+v, the inserted text
looks like this:
^[[200~inserted text~
I therefore added this section to my .zshrc
to prevent this:
_paste-copy-using-xsel() {
LBUFFER+="$(xsel -b -o)"
}
zle -N _paste-copy-using-xsel
bindkey '^v' _paste-copy-using-xsel # Paste
Now I can paste with Ctrl+Shift+v AND Ctrl+v.
But the suggestions are still present after pasting when using Ctrl+v.
Is there a way to make this also work in this case?
System: Manjaro Gnome 42.4, Wayland, Gnome Terminal with oh-my-zsh
Like
worked for me
Pretty sure this started somewhat recently, but now, if I paste something into the terminal and then hit the right arrow on the keyboard, it will append the suggestion that was in terminal before the paste.