diff options
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/substitute.vim | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/plugin/substitute.vim b/plugin/substitute.vim index 47de404..f06afb9 100644 --- a/plugin/substitute.vim +++ b/plugin/substitute.vim @@ -20,6 +20,52 @@ vnoremap <silent> gs :call <SID>v_do_subst_enter()<cr> noremap <silent> gS :set operatorfunc=<SID>do_subst_no_enter<cr>g@ vnoremap <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// + +let s:entered_with_change = v:false +let s:entered_with_append = v:false + +let s:old_word='' +let s:new_word='' + +let s:override_word = '' +function! OverrideChange() + let s:entered_with_change = v:true + let s:override_word = expand('<cword>') + return '' +endfunction + +function! s:save_register_on_change() +endfunction + +function! s:save_old_word() abort + if s:entered_with_change + let s:old_word = s:override_word + else + let s:old_word = expand("<cword>") + endif +endfunction + +function! s:save_new_word() abort + if s:entered_with_change + let s:entered_with_change = v:false + let s:new_word = expand("<cword>") + else + let s:new_word = expand("<cword>") + endif +endfunction + +augroup FieldMarshalSubstitute + au! + autocmd InsertEnter * call s:save_old_word() + autocmd InsertLeave * call s:save_new_word() +augroup END + +noremap <expr> c OverrideChange() . 'c' +noremap <expr> s OverrideChange() . 's' +noremap <expr> a OverrideChange() . 'a' + function! s:do_subst_enter(...) abort call s:do_subst_priv("'[", "']", v:true) endfunction @@ -50,8 +96,8 @@ function! s:do_subst_priv(m0, m1, do_enter) abort \ lnum0, \ lnum1, \ a:do_enter ? "\\<" : "", - \ escape(@", '/\'), + \ escape(s:old_word, '/\'), \ a:do_enter ? "\\>" : "", - \ escape(@., '/\'), + \ escape(s:new_word, '/\'), \ a:do_enter ? "\n" : "")) endfunction |