aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fall.vim8
-rw-r--r--plugin/substitute.vim23
2 files changed, 29 insertions, 2 deletions
diff --git a/plugin/fall.vim b/plugin/fall.vim
index 8de1780..a3eb2c5 100644
--- a/plugin/fall.vim
+++ b/plugin/fall.vim
@@ -35,6 +35,14 @@ vnoremap <silent> ii <cmd>exec "normal! "
\ . "kO"
\ . fall#fall('k', '^\s*$') . 'j' <cr>
+" Selects "vertical words"
+vnoremap <expr> <silent> iv fall#visual_vertical_word("jk", '\k')
+onoremap <silent> iv <cmd>exec "normal! V" . fall#visual_vertical_word("jk", '\k')<cr>
+
+" Selects "vertical WORDS"
+vnoremap <expr> <silent> iV fall#visual_vertical_word("jk", '\S')
+onoremap <silent> iV <cmd>exec "normal! V" . fall#visual_vertical_word("jk", '\S')<cr>
+
vnoremap <expr> <silent> ic fall#visual_same_character("jk")
onoremap <silent> ic <cmd>exec "normal! V" . fall#visual_same_character("jk")<cr>
diff --git a/plugin/substitute.vim b/plugin/substitute.vim
index 82afab9..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//
@@ -30,7 +30,23 @@ function! s:save_cur_word() abort
let s:current_word = expand("<cword>")
endfunction
+function! s:save_new_word_from_insert() abort
+ 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 = l:new_word
+endfunction
+
function! s:save_new_word() abort
+ " 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
@@ -39,6 +55,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 +76,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 +94,4 @@ function! s:do_subst_priv(m0, m1, do_enter) abort
\ escape(s:new_word, '/\'),
\ a:do_enter ? "\n" : ""))
endfunction
+