From e38c4942f1b92ba374f5b7d165642f16f070ce27 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 16 Sep 2022 20:06:12 +0000 Subject: remappings.vim: add visual redo using the {Visual}dot(.) --- plugin/remappings.vim | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/plugin/remappings.vim b/plugin/remappings.vim index 8b3133a..f29f0a4 100644 --- a/plugin/remappings.vim +++ b/plugin/remappings.vim @@ -4,19 +4,14 @@ " The behavior inside the quotes should remain unchanged. onoremap i" call find_quote('i', '"') onoremap a" call find_quote('a', '"') - onoremap i' call find_quote('i', "'") onoremap a' call find_quote('a', "'") - onoremap i` call find_quote('i', '`') onoremap a` call find_quote('a', '`') - vnoremap i" call find_quote('i', '"') vnoremap a" call find_quote('a', '"') - vnoremap i' call find_quote('i', "'") vnoremap a' call find_quote('a', "'") - vnoremap i` call find_quote('i', '`') vnoremap a` call find_quote('a', '`') @@ -49,3 +44,29 @@ endfunction " Fix silly yank behavior. nnoremap Y y$ + +" . in visual mode will replay the last command on each line in the visual mode. +vnoremap . call visual_repeat() + +function! s:visual_repeat() + exec "normal! \" + + let [_, _, c, _] = getpos('.') + let [b, l1_, _, p] = getpos("'<") + let [_, l2_, _, _] = getpos("'>") + + let l1 = min([l1_, l2_]) + let l2 = max([l1_, l2_]) + + let l = l1 + + while l <= l2 + let newpos = [b, l, c, p] + call setpos('.', newpos) + if newpos == getpos('.') + " Only execute if the new position was valid. + normal! . + endif + let l += 1 + endwhile +endfunction -- cgit