" commentary.vim - Comment stuff out
" Maintainer: Tim Pope
" Version: 1.3
" GetLatestVimScripts: 3695 1 :AutoInstall: commentary.vim
if exists("g:loaded_commentary") || v:version < 703
finish
endif
let g:loaded_commentary = 1
function! s:surroundings() abort
return split(get(b:, 'commentary_format', substitute(substitute(substitute(
\ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '')), '%s', 1)
endfunction
function! s:strip_white_space(l,r,line) abort
let [l, r] = [a:l, a:r]
if l[-1:] ==# ' ' && stridx(a:line,l) == -1 && stridx(a:line,l[0:-2]) == 0
let l = l[:-2]
endif
if r[0] ==# ' ' && (' ' . a:line)[-strlen(r)-1:] != r && a:line[-strlen(r):] == r[1:]
let r = r[1:]
endif
return [l, r]
endfunction
function! s:go(...) abort
if !a:0
let &operatorfunc = matchstr(expand(''), '[^. ]*$')
return 'g@'
elseif a:0 > 1
let [lnum1, lnum2] = [a:1, a:2]
else
let [lnum1, lnum2] = [line("'["), line("']")]
endif
let [l, r] = s:surroundings()
let uncomment = 2
let force_uncomment = a:0 > 2 && a:3
for lnum in range(lnum1,lnum2)
let line = matchstr(getline(lnum),'\S.*\s\@ 2 && l.r !~# '\\'
let line = substitute(line,
\'\M' . substitute(l, '\ze\S\s*$', '\\zs\\d\\*\\ze', '') . '\|' . substitute(r, '\S\zs', '\\zs\\d\\*\\ze', ''),
\'\=substitute(submatch(0)+1-uncomment,"^0$\\|^-\\d*$","","")','g')
endif
if force_uncomment
if line =~ '^\s*' . l
let line = substitute(line,'\S.*\s\@,,0)
xnoremap Commentary go()
nnoremap Commentary go()
nnoremap CommentaryLine go() . '_'
onoremap Commentary :call textobject(get(v:, 'operator', '') ==# 'c')
nnoremap ChangeCommentary c:call textobject(1)
if !hasmapto('Commentary') || maparg('gc','n') ==# ''
xmap gc Commentary
nmap gc Commentary
omap gc Commentary
nmap gcc CommentaryLine
nmap gcu CommentaryCommentary
endif
nmap CommentaryUndo :echoerr "Change your CommentaryUndo map to CommentaryCommentary"
" vim:set et sw=2: