" 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 call change_comment_obj('i') nnoremap cdcc 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@_ function! s:single_character_style(c) return { \ 'block_start_regex': '\(^\s*\(\(\S\)\(' . a:c . '\)\@m>" call search(start_regex, 'bW') exec "normal! m") if getline(sl)[:sc - 2] =~ '^\s*$' && a:iOrA == 'a' && ec >= len(getline(el)) exec "normal V" endif endfunction function! s:change_comment_obj(mv) abort let s = get(s:comment_style, &ft, s:default_style) " U allows ,,etc. to show up in the redo buff. call feedkeys(printf( \ "%s %s %s", \ a:mv, \ s.line, \ repeat("\U\", len(s.line) + 2)), 'n') 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