diff options
Diffstat (limited to 'plugin/remappings.vim')
-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 |