Skip to content

Commit

Permalink
fix: weird behavior after substituting line (#26)
Browse files Browse the repository at this point in the history
This commit fixed the issue that we can't leave insert mode after
typing `S` to substitute current line from normal mode.
  • Loading branch information
jeffreytse committed Feb 26, 2021
1 parent d3b1a54 commit bd5132a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions zsh-vi-mode.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,19 @@ function zvm_open_line_above() {

# Substitute characters of selection
function zvm_vi_substitute() {
# Substitute one character in normal mode
if [[ $ZVM_MODE == $ZVM_MODE_NORMAL ]]; then
BUFFER="${BUFFER:0:$CURSOR}${BUFFER:$((CURSOR+1))}"
zvm_select_vi_mode $ZVM_MODE_INSERT
else
zvm_vi_delete false
zvm_vi_change
fi
zvm_select_vi_mode $ZVM_MODE_INSERT
}

# Substitute all characters of a line
function zvm_vi_substitute_whole_line() {
zvm_select_vi_mode $ZVM_MODE_VISUAL_LINE;
zvm_vi_substitute
}

# Get the beginning and end position of selection
Expand Down Expand Up @@ -1959,6 +1966,7 @@ function zvm_init() {
zvm_define_widget zvm_insert_bol
zvm_define_widget zvm_append_eol
zvm_define_widget zvm_vi_substitute
zvm_define_widget zvm_vi_substitute_whole_line
zvm_define_widget zvm_vi_change
zvm_define_widget zvm_vi_delete
zvm_define_widget zvm_vi_yank
Expand Down Expand Up @@ -2015,6 +2023,7 @@ function zvm_init() {
zvm_bindkey vicmd 'o' zvm_open_line_below
zvm_bindkey vicmd 'O' zvm_open_line_above
zvm_bindkey vicmd 's' zvm_vi_substitute
zvm_bindkey vicmd 'S' zvm_vi_substitute_whole_line
zvm_bindkey visual 'c' zvm_vi_change
zvm_bindkey visual 'd' zvm_vi_delete
zvm_bindkey visual 'y' zvm_vi_yank
Expand Down

0 comments on commit bd5132a

Please sign in to comment.