samer@3: " commentary.vim - Comment stuff out samer@3: " Maintainer: Tim Pope samer@3: " Version: 1.2 samer@3: " GetLatestVimScripts: 3695 1 :AutoInstall: commentary.vim samer@3: samer@3: if exists("g:loaded_commentary") || &cp || v:version < 700 samer@3: finish samer@3: endif samer@3: let g:loaded_commentary = 1 samer@3: samer@3: function! s:surroundings() abort samer@3: return split(get(b:, 'commentary_format', substitute(substitute( samer@3: \ &commentstring, '\S\zs%s',' %s','') ,'%s\ze\S', '%s ', '')), '%s', 1) samer@3: endfunction samer@3: samer@3: function! s:go(type,...) abort samer@3: if a:0 samer@3: let [lnum1, lnum2] = [a:type, a:1] samer@3: else samer@3: let [lnum1, lnum2] = [line("'["), line("']")] samer@3: endif samer@3: samer@3: let [l, r] = s:surroundings() samer@3: let uncomment = 2 samer@3: for lnum in range(lnum1,lnum2) samer@3: let line = matchstr(getline(lnum),'\S.*\s\@ 2 && l.r !~# '\\' samer@3: let line = substitute(line, samer@3: \'\M'.r[0:-2].'\zs\d\*\ze'.r[-1:-1].'\|'.l[0].'\zs\d\*\ze'.l[1:-1], samer@3: \'\=substitute(submatch(0)+1-uncomment,"^0$\\|^-\\d*$","","")','g') samer@3: endif samer@3: if uncomment samer@3: let line = substitute(line,'\S.*\s\@ Commentary :call go(line("'<"),line("'>")) samer@3: nnoremap Commentary :set opfunc=gog@ samer@3: nnoremap CommentaryLine :set opfunc=goexe 'norm! 'v:count1.'g@_' samer@3: onoremap Commentary :call textobject(0) samer@3: nnoremap ChangeCommentary c:call textobject(1) samer@3: nmap CommentaryUndo CommentaryCommentary samer@3: command! -range -bar Commentary call s:go(,) samer@3: samer@3: if !hasmapto('Commentary') || maparg('gc','n') ==# '' samer@3: xmap gc Commentary samer@3: nmap gc Commentary samer@3: omap gc Commentary samer@3: nmap gcc CommentaryLine samer@3: nmap cgc ChangeCommentary samer@3: nmap gcu CommentaryCommentary samer@3: endif samer@3: samer@3: if maparg('\\','n') ==# '' && maparg('\','n') ==# '' && get(g:, 'commentary_map_backslash', 1) samer@3: xmap \\ Commentary:echomsg '\\ is deprecated. Use gc' samer@3: nmap \\ :echomsg '\\ is deprecated. Use gc'Commentary samer@3: nmap \\\ CommentaryLine:echomsg '\\ is deprecated. Use gc' samer@3: nmap \\u CommentaryUndo:echomsg '\\ is deprecated. Use gc' samer@3: endif samer@3: samer@3: " vim:set et sw=2: