diff options
author | Josh Rahm <rahm@google.com> | 2022-09-16 20:06:12 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-09-16 20:06:12 +0000 |
commit | e38c4942f1b92ba374f5b7d165642f16f070ce27 (patch) | |
tree | 7b2707b014887b380fc5a7b2917b91b97d89f0e4 | |
parent | 111dd43954006b254c27a43f6e3b6af57a4c49d8 (diff) | |
download | fieldmarshal.vim-e38c4942f1b92ba374f5b7d165642f16f070ce27.tar.gz fieldmarshal.vim-e38c4942f1b92ba374f5b7d165642f16f070ce27.tar.bz2 fieldmarshal.vim-e38c4942f1b92ba374f5b7d165642f16f070ce27.zip |
remappings.vim: add visual redo using the {Visual}dot(.)
-rw-r--r-- | plugin/remappings.vim | 31 |
1 files 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 <silent> i" <cmd>call <sid>find_quote('i', '"')<cr> onoremap <silent> a" <cmd>call <sid>find_quote('a', '"')<cr> - onoremap <silent> i' <cmd>call <sid>find_quote('i', "'")<cr> onoremap <silent> a' <cmd>call <sid>find_quote('a', "'")<cr> - onoremap <silent> i` <cmd>call <sid>find_quote('i', '`')<cr> onoremap <silent> a` <cmd>call <sid>find_quote('a', '`')<cr> - vnoremap <silent> i" <cmd>call <sid>find_quote('i', '"')<cr> vnoremap <silent> a" <cmd>call <sid>find_quote('a', '"')<cr> - vnoremap <silent> i' <cmd>call <sid>find_quote('i', "'")<cr> vnoremap <silent> a' <cmd>call <sid>find_quote('a', "'")<cr> - vnoremap <silent> i` <cmd>call <sid>find_quote('i', '`')<cr> vnoremap <silent> a` <cmd>call <sid>find_quote('a', '`')<cr> @@ -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 . <cmd>call <sid>visual_repeat()<cr> + +function! s:visual_repeat() + exec "normal! \<esc>" + + 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 |