Skip to content

Commit

Permalink
fix: wrong cursor position after exiting replace mode (#78)
Browse files Browse the repository at this point in the history
The cursor position should go back one character after exiting the
replace mode.
  • Loading branch information
jeffreytse committed Mar 31, 2021
1 parent 15f6a37 commit e4306e4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions zsh-vi-mode.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,10 @@ function zvm_vi_replace() {
zle redisplay
done

# The cursor position should go back one character after
# exiting the replace mode
zle vi-backward-char

zvm_select_vi_mode $ZVM_MODE_NORMAL
zvm_reset_repeat_commands $ZVM_MODE R $cmds
elif [[ $ZVM_MODE == $ZVM_MODE_VISUAL ]]; then
Expand Down Expand Up @@ -1855,6 +1859,7 @@ function zvm_repeat_replace() {

for ((i=1; i<=${#cmds[@]}; i++)); do
cmd="${cmds[$i]}"

# If the cmd or the character at cursor is a newline character,
# or the cursor is at the end of buffer, we should insert the
# cmd instead of replacing with the cmd.
Expand All @@ -1866,9 +1871,14 @@ function zvm_repeat_replace() {
else
BUFFER[$cursor+1]=$cmd
fi

cursor=$((cursor+1))
CURSOR=$cursor
done

# The cursor position should go back one character after
# exiting the replace mode
zle vi-backward-char
}

# Repeat replacing characters
Expand Down

0 comments on commit e4306e4

Please sign in to comment.