From 2cd59fe52c71310139efbdf110c990cbc437ee4d Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Thu, 13 Aug 2026 22:10:46 -0600 Subject: [bugfix] - have substitute work coming out of insert mode. --- plugin/substitute.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'plugin') diff --git a/plugin/substitute.vim b/plugin/substitute.vim index 82afab9..fd8e9ce 100644 --- a/plugin/substitute.vim +++ b/plugin/substitute.vim @@ -30,7 +30,16 @@ function! s:save_cur_word() abort let s:current_word = expand("") endfunction +function! s:save_new_word_from_insert() abort + " The InsertLeave autocmd is fired before before the CursorMoved autocmd, so + " we can use just the current word. + let s:old_word = s:current_word + let s:new_word = expand("") +endfunction + function! s:save_new_word() abort + " The TextChanged autocmd is fired *after* the CursorMoved, so we have to use + " the saved current_word_1 instead of current_word. let s:old_word = s:current_word_1 let s:new_word = expand("") endfunction @@ -39,6 +48,7 @@ augroup FieldMarshalSubstitute au! autocmd CursorMoved * call s:save_cur_word() autocmd TextChanged * call s:save_new_word() + autocmd InsertLeave * call s:save_new_word_from_insert() augroup END function! s:do_subst_enter(...) abort @@ -59,6 +69,7 @@ function! s:v_do_subst_no_enter(...) abort endfunction function! s:do_subst_priv(m0, m1, do_enter) abort + let [_, lnum0, _, _] = getpos(a:m0) let [_, lnum1, _, _] = getpos(a:m1) @@ -76,3 +87,4 @@ function! s:do_subst_priv(m0, m1, do_enter) abort \ escape(s:new_word, '/\'), \ a:do_enter ? "\n" : "")) endfunction + -- cgit