Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entering insert mode with A and auto-suggestion places cursor at next to final character #83

Closed
gotgenes opened this issue Apr 1, 2021 · 7 comments
Assignees
Labels
bug Something isn't working verified This issue was already verified

Comments

@gotgenes
Copy link
Contributor

gotgenes commented Apr 1, 2021

When an auto-suggestion is present, and the user is in normal mode, entering insert mode with A, the cursor will be placed before the final character.

autosuggest

Sequence of events, above:

  1. From insert mode, type echo
  2. zsh auto-suggestion suggests completion with previous command of echo $PATH, cursor remains after the o in echo.
  3. Hit Esc to enter normal mode
  4. Type Shift+A to enter insert mode. Cursor is before the H of $PATH; the expected behavior is the cursor is placed immediately after the H.
  5. Hit Esc to re-enter normal mode, making the cursor position more clear.

The expected behavior is that the cursor would be placed after the final character.

@jeffreytse jeffreytse self-assigned this Apr 2, 2021
@jeffreytse jeffreytse added bug Something isn't working verified This issue was already verified wontfix This will not be worked on and removed bug Something isn't working labels Apr 2, 2021
@jeffreytse
Copy link
Owner

jeffreytse commented Apr 5, 2021

Hi @gotgenes

This behavior is a feature of default zsh-autosuggestions plugin (related code) for easier choosing the auto suggestion. You can config the option ZSH_AUTOSUGGEST_ACCEPT_WIDGETS to change the behavior:

ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
  forward-char
  end-of-line
  vi-forward-char
  vi-end-of-line
  vi-add-eol
)

This widget vi-end-of-line is added by default, you can remove it to settle your issue. Or just move your cursor backward a character (i.e. cursor at h), then press A.

Thanks and regards

@gotgenes
Copy link
Contributor Author

gotgenes commented Apr 5, 2021

Interesting! zsh-vim-mode's behavior is to place the cursor at the end of line (after the auto-suggested text) so I had gotten used to that behavior.

@jeffreytse
Copy link
Owner

Yes, it's better to keep compatibility with the zsh-autosuggestions plugin, and this issue is introduced by zsh-autosuggestions, so you just need to do the simple configuration with ZSH_AUTOSUGGEST_ACCEPT_WIDGETS option, it will be settled down perfectly! : )

@gotgenes
Copy link
Contributor Author

gotgenes commented Apr 5, 2021

Thanks for the suggestion. Just to be clear, the configuration you're suggesting is

ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
    forward-char
    end-of-line
    vi-forward-char
    vi-add-eol
)

Is this correct?

When I use this configuration, and the example above, A places the cursor in insert mode immediately after the o in echo. Is there a configuration that I should use that will make it so A places the cursor after the H in $PATH?

@jeffreytse
Copy link
Owner

jeffreytse commented Apr 5, 2021

Hi @gotgenes , the configuration you provided is correct. For choosing the suggestion, you can use l to instead of A after you setting with the configuration cleared, or you can bind a key to accept the auto suggestion (see here) like below snippet.

# This would bind ctrl + space to accept the current suggestion.
bindkey '^ ' autosuggest-accept

@jeffreytse jeffreytse added bug Something isn't working and removed wontfix This will not be worked on labels Apr 6, 2021
jeffreytse added a commit that referenced this issue Apr 6, 2021
When an auto-suggestion is present, and the user is in normal mode,
entering insert mode with `A`, the cursor will be placed before the
final character, it should be after the final character.
@jeffreytse
Copy link
Owner

jeffreytse commented Apr 6, 2021

Hi @gotgenes

I’m so sorry for misunderstanding your issue, and it's not about choosing the auto-suggestion or not, just about the wrong cursor position. Now this issue has been addressed and fixed, please update your plugin to the latest version.

Thanks and regards

@gotgenes
Copy link
Contributor Author

gotgenes commented Apr 6, 2021

@jeffreytse Thanks for following up! Yes, sorry, I probably could have made the issue clearer.

Confirmed fixed in the latest version!

@gotgenes gotgenes closed this as completed Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working verified This issue was already verified
Projects
None yet
Development

No branches or pull requests

2 participants