From fd5de6e1630c9e3a5966eb4101e376863676e58d Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 8 Mar 2024 19:34:20 +0000 Subject: Bunch of changes. Salient changes are: Get rid of object remapping the quotes (i/a "/'/`) in favor of adding a new text object "next quotes" such as cin"/can"/etc. Added mappings in visual mode that behave like "fall", but for matching characters. So ic will highlight the current character and all of the same character up and down. Super useful for making edits to columns of identical characters. Added a text object ic/ac that highlight all the lines that match. removed the uncommented paragraph text objects as they're broken anyway. --- plugin/commenter.vim | 26 ---------------------- plugin/fall.vim | 9 ++++++++ plugin/remappings.vim | 60 +++++++++++++++++++++------------------------------ 3 files changed, 33 insertions(+), 62 deletions(-) (limited to 'plugin') diff --git a/plugin/commenter.vim b/plugin/commenter.vim index f903fce..8d283c3 100644 --- a/plugin/commenter.vim +++ b/plugin/commenter.vim @@ -13,11 +13,6 @@ vnoremap i/ call comment_obj('', 'i') onoremap a/ call comment_obj(v:operator, 'a') vnoremap a/ call comment_obj('', 'a') -" Objects for paragraphs excluding any comment blocks immediately preceeding or -" Succeeding -onoremap acp call uncommented_paragraph('a') -onoremap icp call uncommented_paragraph('i') - noremap czd set operatorfunc=uncommentg@ nnoremap czdd set operatorfunc=uncommentg@_ @@ -71,27 +66,6 @@ function! s:minpos(cur, oth) endfunction -function! s:uncommented_paragraph(t) abort - let savepos = getpos('.') - set operatorfunc=s:save_object - exec "normal! g@". a:t . "pv\" - call setpos('.', savepos) - - let [start_regex, end_regex] = g:GetCommentRegex('a') - - call search(end_regex . '\|\%^', 'cb') - exec "normal! j" - call setpos('.', s:maxpos(getpos('.'), s:object.start)) - normal! m< - call setpos('.', savepos) - - call search(start_regex . '\|\%$', 'c') - call setpos('.', s:minpos(getpos('.'), s:object.end)) - exec "normal! k" - - normal! m>gvV -endfunction - function! s:regex_combine(s1, s2) abort if a:s1 == "" return a:s2 diff --git a/plugin/fall.vim b/plugin/fall.vim index 0001c37..8de1780 100644 --- a/plugin/fall.vim +++ b/plugin/fall.vim @@ -34,3 +34,12 @@ vnoremap ii exec "normal! " \ . fall#fall('j', '^\s*$') \ . "kO" \ . fall#fall('k', '^\s*$') . 'j' + +vnoremap ic fall#visual_same_character("jk") +onoremap ic exec "normal! V" . fall#visual_same_character("jk") + +vnoremap ijc fall#visual_same_character("j") +onoremap ijc exec "normal! V" . fall#visual_same_character("j") + +vnoremap ikc fall#visual_same_character("k") +onoremap ikc exec "normal! V" . fall#visual_same_character("k") diff --git a/plugin/remappings.vim b/plugin/remappings.vim index f29f0a4..90d12e0 100644 --- a/plugin/remappings.vim +++ b/plugin/remappings.vim @@ -2,43 +2,31 @@ " 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' +onoremap in" call find_next_quote('i', '"') +onoremap an" call find_next_quote('a', '"') +onoremap in' call find_next_quote('i', "'") +onoremap an' call find_next_quote('a', "'") +onoremap in` call find_next_quote('i', '`') +onoremap an` call find_next_quote('a', '`') +vnoremap in" call find_next_quote('i', '"') +vnoremap an" call find_next_quote('a', '"') +vnoremap in' call find_next_quote('i', "'") +vnoremap an' call find_next_quote('a', "'") +vnoremap in` call find_next_quote('i', '`') +vnoremap an` call find_next_quote('a', '`') + +function! s:find_next_quote(ai, q) abort + call search(a:q, '') + call search(a:q, '') + + let l = getline(line('.')) + let c = col('.') - 1 + + if l[c] == a:q && l[c - 1] == a:q + exec "normal! i " + elseif l[c] == a:q && l[c + 1] == a:q + exec "normal! a l" endif - - exec "normal! \" - call search(a:q . '\zs.', flags) exec "normal! v" . a:ai . a:q endfunction -- cgit