diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2026-08-13 22:20:44 -0600 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2026-08-13 22:20:44 -0600 |
| commit | 46b837abe3471cab44156a5528864853eedac077 (patch) | |
| tree | f8130f404f1e34f126b774090553cf662b929910 /plugin | |
| parent | 2cd59fe52c71310139efbdf110c990cbc437ee4d (diff) | |
| download | fieldmarshal.vim-46b837abe3471cab44156a5528864853eedac077.tar.gz fieldmarshal.vim-46b837abe3471cab44156a5528864853eedac077.tar.bz2 fieldmarshal.vim-46b837abe3471cab44156a5528864853eedac077.zip | |
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/substitute.vim | 21 |
1 files changed, 14 insertions, 7 deletions
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 <silent> gs :set operatorfunc=<SID>do_subst_enter<cr>g@ -vnoremap <silent> gs :call <SID>v_do_subst_enter()<cr> +xnoremap <silent> gs :call <SID>v_do_subst_enter()<cr> " 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 <silent> gS :set operatorfunc=<SID>do_subst_no_enter<cr>g@ -vnoremap <silent> gS :call <SID>v_do_subst_no_enter()<cr> +xnoremap <silent> gS :call <SID>v_do_subst_no_enter()<cr> " Hotkey for replacing the most recently searched matches. noremap <C-s> <esc>:<C-u>%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("<cword>") + + " 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("<cword>") + 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("<cword>") endfunction |