diff options
author | Josh Rahm <rahm@google.com> | 2024-03-08 19:34:20 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2024-03-08 19:34:20 +0000 |
commit | fd5de6e1630c9e3a5966eb4101e376863676e58d (patch) | |
tree | b6d483804abee1d6888e2e77819755877c332f12 | |
parent | c8ef92cfb59f28c050b82e90fb813d25392e6664 (diff) | |
download | fieldmarshal.vim-fd5de6e1630c9e3a5966eb4101e376863676e58d.tar.gz fieldmarshal.vim-fd5de6e1630c9e3a5966eb4101e376863676e58d.tar.bz2 fieldmarshal.vim-fd5de6e1630c9e3a5966eb4101e376863676e58d.zip |
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 <C-v>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.
-rw-r--r-- | autoload/fall.vim | 38 | ||||
-rw-r--r-- | autoload/hints/plugins.vim | 19 | ||||
-rw-r--r-- | autoload/subwords.vim | 5 | ||||
-rw-r--r-- | plugin/commenter.vim | 26 | ||||
-rw-r--r-- | plugin/fall.vim | 9 | ||||
-rw-r--r-- | plugin/remappings.vim | 60 |
6 files changed, 85 insertions, 72 deletions
diff --git a/autoload/fall.vim b/autoload/fall.vim index 493ded3..feccc1a 100644 --- a/autoload/fall.vim +++ b/autoload/fall.vim @@ -77,4 +77,40 @@ function! fall#fall(dir, pattern) abort endwhile return "m'" . n . a:dir -endfunction! +endfunction + +function! fall#visual_same_character(dir) + let start_line = line(".") + let line = start_line + let column = col(".") + let char_to_match = matchstr(getline(line), '\%' . column . 'c.') + + let expr = "" + + if a:dir =~ 'k' + while line > 1 + let line -= 1 + if matchstr(getline(line), '\%' . column . 'c.') != char_to_match + break + endif + let expr .= 'k' + endwhile + endif + + if a:dir == 'jk' + let expr .= 'o' + let line = start_line + endif + + if a:dir =~ 'j' + while line <= line("$") + let line += 1 + if matchstr(getline(line), '\%' . column . 'c.') != char_to_match + break + endif + let expr .= 'j' + endwhile + endif + + return expr +endfunction diff --git a/autoload/hints/plugins.vim b/autoload/hints/plugins.vim index e3e5a9d..db08535 100644 --- a/autoload/hints/plugins.vim +++ b/autoload/hints/plugins.vim @@ -16,16 +16,17 @@ endfunction let s:WHITESPACE_OR_COMMENT='\(^\s*$\)\|\(^\s*//\)\|\(^\s*\*/\)' function! s:java_plugin.TagLine(linenr, line) dict - if self.last_line =~ s:WHITESPACE_OR_COMMENT - \ && !(a:line =~ s:WHITESPACE_OR_COMMENT) - let self.last_line = a:line - return v:true - endif - let self.last_line = a:line + return v:true + # if self.last_line =~ s:WHITESPACE_OR_COMMENT + # \ && !(a:line =~ s:WHITESPACE_OR_COMMENT) + # let self.last_line = a:line + # return v:true + # endif + # let self.last_line = a:line - return - \ a:line =~ '^\s*}$' || - \ a:line =~ '\<\(public\|private\|protected\|class\|static\|try\|while\|for\|if\|else\|catch\)\>' + # return + # \ a:line =~ '^\s*}$' || + # \ a:line =~ '\<\(public\|private\|protected\|class\|static\|try\|while\|for\|if\|else\|catch\)\>' endfunction function! hints#plugins#registerFt(filetype, plugin) abort diff --git a/autoload/subwords.vim b/autoload/subwords.vim index eef8f8b..2c5c0bc 100644 --- a/autoload/subwords.vim +++ b/autoload/subwords.vim @@ -49,6 +49,11 @@ function! subwords#next(vis, forward) let s:subword_nosave = 0 endfunction +" Zero-match the next subword baundary for repeatable cin- and cin_ commands. +function! subwords#visual_beginning(prefer_camel, around) + return subwords#visual(a:prefer_camel, a:around) . "oi v" +endfunction + " Visually highlights a subword. " " If a:prefer_camel is set, then WordsLike_This will be interpreted with 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/ <cmd>call <sid>comment_obj('', 'i')<cr> onoremap a/ <cmd>call <sid>comment_obj(v:operator, 'a')<cr> vnoremap a/ <cmd>call <sid>comment_obj('', 'a')<cr> -" Objects for paragraphs excluding any comment blocks immediately preceeding or -" Succeeding -onoremap acp <cmd>call <sid>uncommented_paragraph('a')<cr> -onoremap icp <cmd>call <sid>uncommented_paragraph('i')<cr> - noremap czd <cmd>set operatorfunc=<sid>uncomment<cr>g@ nnoremap czdd <cmd>set operatorfunc=<sid>uncomment<cr>g@_ @@ -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\<esc>" - 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 <silent> ii <cmd>exec "normal! " \ . fall#fall('j', '^\s*$') \ . "kO" \ . fall#fall('k', '^\s*$') . 'j' <cr> + +vnoremap <expr> <silent> ic fall#visual_same_character("jk") +onoremap <silent> ic <cmd>exec "normal! V" . fall#visual_same_character("jk")<cr> + +vnoremap <expr> <silent> ijc fall#visual_same_character("j") +onoremap <silent> ijc <cmd>exec "normal! V" . fall#visual_same_character("j")<cr> + +vnoremap <expr> <silent> ikc fall#visual_same_character("k") +onoremap <silent> ikc <cmd>exec "normal! V" . fall#visual_same_character("k")<cr> 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 <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> - -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 <silent> in" <cmd>call <sid>find_next_quote('i', '"')<cr> +onoremap <silent> an" <cmd>call <sid>find_next_quote('a', '"')<cr> +onoremap <silent> in' <cmd>call <sid>find_next_quote('i', "'")<cr> +onoremap <silent> an' <cmd>call <sid>find_next_quote('a', "'")<cr> +onoremap <silent> in` <cmd>call <sid>find_next_quote('i', '`')<cr> +onoremap <silent> an` <cmd>call <sid>find_next_quote('a', '`')<cr> +vnoremap <silent> in" <cmd>call <sid>find_next_quote('i', '"')<cr> +vnoremap <silent> an" <cmd>call <sid>find_next_quote('a', '"')<cr> +vnoremap <silent> in' <cmd>call <sid>find_next_quote('i', "'")<cr> +vnoremap <silent> an' <cmd>call <sid>find_next_quote('a', "'")<cr> +vnoremap <silent> in` <cmd>call <sid>find_next_quote('i', '`')<cr> +vnoremap <silent> an` <cmd>call <sid>find_next_quote('a', '`')<cr> + +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! \<esc>" - call search(a:q . '\zs.', flags) exec "normal! v" . a:ai . a:q endfunction |