From 445bdd5b7c8794b7961926dbe660970ff5df5373 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Thu, 15 Sep 2022 12:44:54 -0600 Subject: remappings.vim: common remappings remap the text objects for ", ' and ` to go to the next string even if the next string is not on the same line. also add nnoremap Y y$ for good measure. --- plugin/remappings.vim | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 plugin/remappings.vim (limited to 'plugin') diff --git a/plugin/remappings.vim b/plugin/remappings.vim new file mode 100644 index 0000000..8b3133a --- /dev/null +++ b/plugin/remappings.vim @@ -0,0 +1,51 @@ + +" Remap i{",',`} and a{",',`} to search for the next string. This is more like how objects like i( and i{ work. +" +" 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', '`') + +function! s:find_quote(ai, q) abort + let l = getline('.')[:col('.') - 2] + + let cnt = 0 + let skip = 0 + for c in l + if c ==# a:q && !skip + let cnt = !cnt + endif + + if c ==# '\' + let skip = 1 + else + let skip = 0 + endif + endfor + + let flags = 'W' + if cnt == 1 + let flags .= 'b' + endif + + exec "normal! \" + call search(a:q . '\zs.', flags) + exec "normal! v" . a:ai . a:q +endfunction + +" Fix silly yank behavior. +nnoremap Y y$ -- cgit