zsh-vi-mode icon indicating copy to clipboard operation
zsh-vi-mode copied to clipboard

Cursor should move to the end of line when using up/down arrows to look at previous commands

Open oars opened this issue 3 years ago • 12 comments

oars avatar Feb 10 '21 19:02 oars

Hi @oars

In fact, the cursor will be move to the end of line when using up/down arrows to look at previous commands. But this is weird your side didn't reach this result. Could you provide me further instructions?

Thanks and regards

jeffreytse avatar Feb 11 '21 03:02 jeffreytse

Thanks, for some reason in my case the cursor is at the start of the previous commands, not at the end.

oars avatar Feb 17 '21 20:02 oars

I have the same problem, up arrow correctly pastes in previous command, but cursor stays at the beginning of the line. ctrl-p works correctly.

1m0d avatar Feb 26 '21 14:02 1m0d

Hi @1m0d

👍 Thanks for the reporting, I'll try to figure out this issue. Any progress I will update here. Also welcome to star this project for further updates in the future.

Thanks and regards

jeffreytse avatar Feb 26 '21 15:02 jeffreytse

Hi @1m0d

In fact, the Arrow Up/Down is for partial history search feature, that is the same beginning (based at cursor) of commands in history (#15), if you just want to move to previous command in the history, you should use ctrl-p or k (just available in normal mode).

Thanks and regards

jeffreytse avatar Feb 26 '21 15:02 jeffreytse

By default up arrow is set to up-line-or-history in zsh which you overwrite to history-beginning-search-backward, which has an alternative history-search-backward in which the cursor goes to the end of the line. I do not recommend overwriting default keybinds, but if you do I recommend using history-search-backward so the cursor goes to the end of the line as expected by default.

In case this does not get changed users can just put

bindkey "^[[A" up-line-or-history
bindkey "^[[B" down-line-or-history

or

bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward

to their .zshrc if they want the cursor to go to the end of line.

Edit: Unfortunately even if you set it in .zshrc, the plugin overwrites the bindings.

1m0d avatar Feb 26 '21 15:02 1m0d

Hi @1m0d

Thank you for your detailed explanation, I will consider your comments carefully. You should execute your custom keybindings after this plugin initialized (See here).

Thanks and regards

jeffreytse avatar Feb 26 '21 17:02 jeffreytse

Yes, I missed that part, thank you.

1m0d avatar Feb 26 '21 17:02 1m0d

Hi @1m0d @oars

This commit 84b88a4 has revert the bindings of Arrow Up/Down to the default, as that's what most Vi users will expect. And you don't need to do the bindings again in zvm_after_init function.

Thanks and regards

jeffreytse avatar Mar 04 '21 02:03 jeffreytse

Hi @oars

Could you have a check with the latest version for this issue? And the issue will be closed if there is no more requests.

Thanks and regards

jeffreytse avatar Mar 15 '21 01:03 jeffreytse

Edit: Unfortunately even if you set it in .zshrc, the plugin overwrites the bindings.

@1m0d I've managed to fix this behaviour by adding the following at the end of my .zshrc

zvm_after_init_commands+=("bindkey '^[[A' up-line-or-search" "bindkey '^[[B' down-line-or-search")

pawurb avatar Jun 01 '21 13:06 pawurb

Edit: Unfortunately even if you set it in .zshrc, the plugin overwrites the bindings.

@1m0d I've managed to fix this behaviour by adding the following at the end of my .zshrc

zvm_after_init_commands+=("bindkey '^[[A' up-line-or-search" "bindkey '^[[B' down-line-or-search")

@pawurb, In case of something incompatible, I suggest you use the zvm_bindkey command to do the binding as the document snippet.

jeffreytse avatar Jun 01 '21 16:06 jeffreytse