" Function for commenting out blocks of text. noremap cd set operatorfunc=commentg@ nnoremap cdd set operatorfunc=commentg@_ nnoremap cD set operatorfunc=commentg@$ " Comment out the rest of the line and put the cursor into insert mode nnoremap cdC c(comment-change-object-i) " Comment out the line and go into insert mode before the first non-blank " character. nnoremap cdcc c(comment-change-object-I) onoremap (comment-change-object-i) call change_comment_obj('i') onoremap (comment-change-object-I) call change_comment_obj('I') onoremap i/ call comment_obj(v:operator, 'i') vnoremap i/ call comment_obj('', 'i') onoremap a/ call comment_obj(v:operator, 'a') vnoremap a/ call comment_obj('', 'a') noremap czd set operatorfunc=uncommentg@ nnoremap czdd set operatorfunc=uncommentg@_ let s:default_style = { \ 'block_start_regex': '\(^\s*\(\(\S\)\(#\)\@m>" call search(start_regex, 'bW') exec "normal! m") if getline(sl)[:sc - 2] =~ '^\s*$' && a:iOrA == 'a' && ec >= len(getline(el)) " Select line-wise if the comments on on lines. exec "normal V" endif endfunction function! s:change_comment_obj(mv) abort if v:operator == 'c' " This is a cheese to allow the cdcc and cdC commands to be repeated with " the dot operator. When in insert mode stop " recording into the redobuff. This is a way to get around that. let s = get(s:comment_style, &ft, s:default_style) exec printf("normal! %s %s \%dhvl", a:mv, s.line, len(s.line) + 3) else endif endfunction let s:comment_style = { \ 'java,c,cpp,rust,go': { \ 'multi_start_regex': '${as}\/\*\([*]\|\_s\)*${is}\S', \ 'multi_end_regex': '${is}\S\_s*\*\/${as}', \ 'block_start_regex': '\(^\s*\(\(\S\S\)\(\/\/\)\@ 1 for l in ls if ! (l =~ '^\s*$') let sz = match(l, '^\(\s\+\)\zs\S\ze') + 1 if sz <= 0 let sz = 1 endif if sz < smallest && sz > 0 let smallest = sz endif endif endfor if self.arg == 'line' let i = 0 while i < len(ls) let ls[i] = substitute(ls[i], printf('\%%%dc', smallest), s.line . ' ', '') let i += 1 endwhile else if self.arg != 'line' && !has_key(s, 'multi_start') throw "Inline comments not allowed" endif let ls[0] = substitute(ls[0], '^', s.multi_start . ' ', '') let ls[-1] = substitute(ls[-1], '$', ' ' . s.multi_end, '') endif else let l = getline('.') if l[len(l) - len(ls[0]):] ==# ls[0] let ls[0] = printf("%s %s", s.line, ls[0]) else if !has_key(s, 'multi_start') throw "Inline comments not allowed" endif let ls[0] = printf("%s %s %s", s.multi_start, ls[0], s.multi_end) endif endif return ls endfunction call fieldmarshal#modifytext(a:arg, cb) norm `` endfunction