aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2026-08-13 22:10:46 -0600
committerJosh Rahm <joshuarahm@gmail.com>2026-08-13 22:10:46 -0600
commit2cd59fe52c71310139efbdf110c990cbc437ee4d (patch)
tree4b2f9a5d9ec874bf953598eab678e0f39fe20113
parent94de573c7f05582cb2ab6e2a7cb81cca31ba6453 (diff)
downloadfieldmarshal.vim-2cd59fe52c71310139efbdf110c990cbc437ee4d.tar.gz
fieldmarshal.vim-2cd59fe52c71310139efbdf110c990cbc437ee4d.tar.bz2
fieldmarshal.vim-2cd59fe52c71310139efbdf110c990cbc437ee4d.zip
[bugfix] - have substitute work coming out of insert mode.
-rw-r--r--plugin/substitute.vim12
1 files changed, 12 insertions, 0 deletions
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("<cword>")
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("<cword>")
+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("<cword>")
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
+