From 46b837abe3471cab44156a5528864853eedac077 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Thu, 13 Aug 2026 22:20:44 -0600 Subject: [feat] small chatgpt recs. --- plugin/substitute.vim | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'plugin') diff --git a/plugin/substitute.vim b/plugin/substitute.vim index fd8e9ce..c1dc03f 100644 --- a/plugin/substitute.vim +++ b/plugin/substitute.vim @@ -7,14 +7,14 @@ " otherwise in a text body. noremap gs :set operatorfunc=do_subst_enterg@ -vnoremap gs :call v_do_subst_enter() +xnoremap gs :call v_do_subst_enter() " gS is like gs, except it: " " * doesn't feed a newline at the end " * doesn't wrap the string to substitue in word boundaries. noremap gS :set operatorfunc=do_subst_no_enterg@ -vnoremap gS :call v_do_subst_no_enter() +xnoremap gS :call v_do_subst_no_enter() " Hotkey for replacing the most recently searched matches. noremap :%s// @@ -31,15 +31,22 @@ function! s:save_cur_word() abort 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 l:new_word = expand("") + + " Don't replace the last useful substitution with foo -> foo. + if l:new_word ==# s:current_word + return + endif + + " InsertLeave happens before CursorMoved. let s:old_word = s:current_word - let s:new_word = expand("") + let s:new_word = l:new_word 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. + " For a normal-mode change CursorMoved fires first, so current_word now + " describes the post-change cursor position. current_word_1 is therefore + " the word from immediately before the change. let s:old_word = s:current_word_1 let s:new_word = expand("") endfunction -- cgit