Skip to content

Commit

Permalink
fix(vi-mode): fix cursor change on visual mode (#11586)
Browse files Browse the repository at this point in the history
Fixes #11586
  • Loading branch information
mcornella committed Apr 2, 2023
1 parent 68005b8 commit f7d903f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/vi-mode/vi-mode.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ function _vi-mode-set-cursor-shape-for-keymap() {
printf $'\e[%d q' "${_shape}"
}

function _visual-mode {
typeset -g VI_KEYMAP=visual
_vi-mode-set-cursor-shape-for-keymap "$VI_KEYMAP"
zle .visual-mode
}
zle -N visual-mode _visual-mode

function _vi-mode-should-reset-prompt() {
# If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE is unset (default), dynamically
# check whether we're using the prompt to display vi-mode info
Expand Down

4 comments on commit f7d903f

@arkosno
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent work on the fix :) , unrelated but is there a way to map ii in visual mode to escape into normal mode?

@mcornella
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arkosno you could run the code below or put it in your zshrc file:

bindkey -M visual ii .vi-cmd-mode

Either way, many bindkeys in normal mode already work in visual mode. You can check bindkeys for a specific keymap with the bindkey -M command, like so:

bindkey -M visual
bindkey -M vicmd

@arkosno
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason it's not working, I get an error sound and nothing happens but when I check bindkey -M visual, the setting is there as implemented.

@mcornella
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you are really in visual mode. To enter you should press v from the normal mode, and pressing left/right arrows should highlight more characters.

Please sign in to comment.