" tComment.vim -- An easily extensible & universal comment plugin " @Author: Tom Link (micathom AT gmail com) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Created: 27-Dez-2004. " @Last Change: 2015-04-26. " @Revision: 964 " GetLatestVimScripts: 1173 1 tcomment.vim if &cp || exists('loaded_tcomment') finish endif let loaded_tcomment = 307 let s:save_cpo = &cpo set cpo&vim if !exists('g:tcommentMaps') " If true, set maps. let g:tcommentMaps = 1 "{{{2 endif if !exists("g:tcommentMapLeader1") " g:tcommentMapLeader1 should be a shortcut that can be used with " map, imap, vmap. let g:tcommentMapLeader1 = '' "{{{2 endif if !exists("g:tcommentMapLeader2") " g:tcommentMapLeader2 should be a shortcut that can be used with " map, xmap. let g:tcommentMapLeader2 = '_' "{{{2 endif if !exists("g:tcommentMapLeaderOp1") " See |tcomment-operator|. let g:tcommentMapLeaderOp1 = 'gc' "{{{2 endif if !exists("g:tcommentMapLeaderUncommentAnyway") " See |tcomment-operator|. let g:tcommentMapLeaderUncommentAnyway = 'g<' "{{{2 endif if !exists("g:tcommentMapLeaderCommentAnyway") " See |tcomment-operator|. let g:tcommentMapLeaderCommentAnyway = 'g>' "{{{2 endif if !exists('g:tcommentTextObjectInlineComment') let g:tcommentTextObjectInlineComment = 'ic' "{{{2 endif " :display: :[range]TComment[!] ?ARGS... " If there is a visual selection that begins and ends in the same line, " then |:TCommentInline| is used instead. " The optional range defaults to the current line. With a bang '!', " always comment the line. " " ARGS... are either (see also |tcomment#Comment()|): " 1. a list of key=value pairs " 2. 1-2 values for: ?commentBegin, ?commentEnd command! -bar -bang -range -nargs=* -complete=customlist,tcomment#CompleteArgs TComment \ keepjumps call tcomment#Comment(, , 'G', "", ) " :display: :[range]TCommentAs[!] commenttype ?ARGS... " TCommentAs requires g:tcomment_{filetype} to be defined. " With a bang '!', always comment the line. " " ARGS... are either (see also |tcomment#Comment()|): " 1. a list of key=value pairs " 2. 1-2 values for: ?commentBegin, ?commentEnd command! -bar -bang -complete=customlist,tcomment#Complete -range -nargs=+ TCommentAs \ call tcomment#CommentAs(, , "", ) " :display: :[range]TCommentRight[!] ?ARGS... " Comment the text to the right of the cursor. If a visual selection was " made (be it block-wise or not), all lines are commented out at from " the current cursor position downwards. " With a bang '!', always comment the line. " " ARGS... are either (see also |tcomment#Comment()|): " 1. a list of key=value pairs " 2. 1-2 values for: ?commentBegin, ?commentEnd command! -bar -bang -range -nargs=* -complete=customlist,tcomment#CompleteArgs TCommentRight \ keepjumps call tcomment#Comment(, , 'R', "", ) " :display: :[range]TCommentBlock[!] ?ARGS... " Comment as "block", e.g. use the {&ft}_block comment style. The " commented text isn't indented or reformated. " With a bang '!', always comment the line. " " ARGS... are either (see also |tcomment#Comment()|): " 1. a list of key=value pairs " 2. 1-2 values for: ?commentBegin, ?commentEnd command! -bar -bang -range -nargs=* -complete=customlist,tcomment#CompleteArgs TCommentBlock \ keepjumps call tcomment#Comment(, , 'B', "", ) " :display: :[range]TCommentInline[!] ?ARGS... " Use the {&ft}_inline comment style. " With a bang '!', always comment the line. " " ARGS... are either (see also |tcomment#Comment()|): " 1. a list of key=value pairs " 2. 1-2 values for: ?commentBegin, ?commentEnd command! -bar -bang -range -nargs=* -complete=customlist,tcomment#CompleteArgs TCommentInline \ keepjumps call tcomment#Comment(, , 'I', "", ) " :display: :[range]TCommentMaybeInline[!] ?ARGS... " With a bang '!', always comment the line. " " ARGS... are either (see also |tcomment#Comment()|): " 1. a list of key=value pairs " 2. 1-2 values for: ?commentBegin, ?commentEnd command! -bar -bang -range -nargs=* -complete=customlist,tcomment#CompleteArgs TCommentMaybeInline \ keepjumps call tcomment#Comment(, , 'i', "", ) " command! -range TCommentMap call tcomment#ResetOption() | noremap TComment_ :TComment vnoremap TComment_ :TCommentMaybeInline inoremap TComment_ :TComment noremap TComment_p m`vip:TComment`` inoremap TComment_p :norm! m`vip:TComment`` noremap TComment_ :TComment inoremap TComment_ :TComment inoremap TComment_r :TCommentRight noremap TComment_r :TCommentRight vnoremap TComment_i :TCommentInline noremap TComment_i v:TCommentInline mode=I# inoremap TComment_i v:TCommentInline mode=# noremap TComment_b :TCommentBlock inoremap TComment_b :TCommentBlock mode=# noremap TComment_a :TCommentAs inoremap TComment_a :TCommentAs noremap TComment_n :TCommentAs =&ft inoremap TComment_n :TCommentAs =&ft noremap TComment_s :TCommentAs =&ft_ inoremap TComment_s :TCommentAs =&ft_ noremap TComment_cc :call tcomment#SetOption("count", v:count1) noremap TComment_ca :call tcomment#SetOption("as", input("Comment as: ", &filetype, "customlist,tcomment#Complete")) noremap TComment___ :TComment xnoremap TComment___ :TCommentMaybeInline noremap TComment__p vip:TComment noremap TComment__ :TComment xnoremap TComment__i :TCommentInline noremap TComment__r :TCommentRight noremap TComment__b :TCommentBlock noremap TComment__a :TCommentAs noremap TComment__n :TCommentAs =&ft noremap TComment__s :TCommentAs =&ft_ " function! TCommentOp(type) "{{{3 " " TLogVAR a:type, v:count " " echom "DBG TCommentOp" g:tcomment_ex " " echom "DBG TCommentOp" g:tcomment_op " exec g:tcomment_ex " call call(g:tcomment_op, [a:type]) " endf function! s:MapOp(name, extra, op, invoke) "{{{3 let opfunc = 'TCommentOpFunc_'. substitute(a:name, '[^a-zA-Z0-9_]', '_', 'G') let fn = [ \ 'function! '. opfunc .'(...)', \ 'call tcomment#MaybeReuseOptions('. string(opfunc) .')', \ a:extra, \ 'return call('. string(a:op) .', a:000)', \ 'endf' \ ] exec join(fn, "\n") exec printf('nnoremap TComment_%s '. \ ':call tcomment#ResetOption() \| if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| let w:tcommentPos = getpos(".") \|'. \ 'set opfunc=%s%s', \ a:name, opfunc, a:invoke) endf call s:MapOp('Uncomment', 'call tcomment#SetOption("mode_extra", "U")', 'tcomment#Operator', 'g@') call s:MapOp('Uncommentc', 'call tcomment#SetOption("mode_extra", "U")', 'tcomment#OperatorLine', 'g@$') call s:MapOp('Uncommentb', 'call tcomment#SetOption("mode_extra", "UB")', 'tcomment#OperatorLine', 'g@') xnoremap TComment_Uncomment :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| call tcomment#SetOption("mode_extra", "U") \| '<,'>TCommentMaybeInline call s:MapOp('Comment', '', 'tcomment#OperatorAnyway', 'g@') call s:MapOp('Commentc', '', 'tcomment#OperatorLineAnyway', 'g@$') call s:MapOp('Commentb', 'call tcomment#SetOption("mode_extra", "B")', 'tcomment#OperatorLine', 'g@') xnoremap TComment_Comment :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| '<,'>TCommentMaybeInline! vnoremap TComment_ic :call tcomment#TextObjectInlineComment() noremap TComment_ic :call tcomment#TextObjectInlineComment() call s:MapOp('gcc', '', 'tcomment#OperatorLine', 'g@$') call s:MapOp('gcb', 'call tcomment#SetOption("mode_extra", "B")', 'tcomment#OperatorLine', 'g@') xnoremap TComment_gc :TCommentMaybeInline call s:MapOp('gc', '', 'tcomment#Operator', 'g@') for s:i in range(1, 9) exec 'noremap TComment_' . s:i . ' :call tcomment#SetOption("count", '. s:i .')' exec 'inoremap TComment_' . s:i . ' :call tcomment#SetOption("count", '. s:i .')' exec 'vnoremap TComment_' . s:i . ' :call tcomment#SetOption("count", '. s:i .')' endfor for s:i in range(1, 9) call s:MapOp('gc' . s:i .'c', 'call tcomment#SetOption("count", '. s:i .')', 'tcomment#Operator', 'g@') endfor unlet s:i delfun s:MapOp if g:tcommentMaps if g:tcommentMapLeader1 != '' exec 'map '. g:tcommentMapLeader1 . g:tcommentMapLeader1 .' TComment_' exec 'vmap '. g:tcommentMapLeader1 . g:tcommentMapLeader1 .' TComment_' exec 'imap '. g:tcommentMapLeader1 . g:tcommentMapLeader1 .' TComment_' exec 'map '. g:tcommentMapLeader1 .'p TComment_p' exec 'imap '. g:tcommentMapLeader1 .'p TComment_p' exec 'map '. g:tcommentMapLeader1 .' TComment_' exec 'imap '. g:tcommentMapLeader1 .' TComment_' exec 'imap '. g:tcommentMapLeader1 .'r TComment_r' exec 'map '. g:tcommentMapLeader1 .'r TComment_r' exec 'vmap '. g:tcommentMapLeader1 .'i TComment_i' exec 'map '. g:tcommentMapLeader1 .'i TComment_i' exec 'imap '. g:tcommentMapLeader1 .'i TComment_i' exec 'map '. g:tcommentMapLeader1 .'b TComment_b' exec 'imap '. g:tcommentMapLeader1 .'b TComment_b' exec 'map '. g:tcommentMapLeader1 .'a TComment_a' exec 'imap '. g:tcommentMapLeader1 .'a TComment_a' exec 'map '. g:tcommentMapLeader1 .'n TComment_n' exec 'imap '. g:tcommentMapLeader1 .'n TComment_n' exec 'map '. g:tcommentMapLeader1 .'s TComment_s' exec 'imap '. g:tcommentMapLeader1 .'s TComment_s' exec 'map '. g:tcommentMapLeader1 .'cc TComment_cc' exec 'map '. g:tcommentMapLeader1 .'ca TComment_ca' for s:i in range(1, 9) exec 'map '. g:tcommentMapLeader1 . s:i .' TComment_'.s:i exec 'imap '. g:tcommentMapLeader1 . s:i .' TComment_'.s:i exec 'vmap '. g:tcommentMapLeader1 . s:i .' TComment_'.s:i endfor unlet s:i endif if g:tcommentMapLeader2 != '' exec 'map '. g:tcommentMapLeader2 .'_ TComment___' exec 'xmap '. g:tcommentMapLeader2 .'_ TComment___' exec 'map '. g:tcommentMapLeader2 .'p TComment__p' exec 'map '. g:tcommentMapLeader2 .' TComment__' exec 'xmap '. g:tcommentMapLeader2 .'i TComment__i' exec 'map '. g:tcommentMapLeader2 .'r TComment__r' exec 'map '. g:tcommentMapLeader2 .'b TComment__b' exec 'map '. g:tcommentMapLeader2 .'a TComment__a' exec 'map '. g:tcommentMapLeader2 .'n TComment__n' exec 'map '. g:tcommentMapLeader2 .'s TComment__s' endif if g:tcommentMapLeaderOp1 != '' exec 'nmap '. g:tcommentMapLeaderOp1 .' TComment_gc' for s:i in range(1, 9) exec 'nmap '. g:tcommentMapLeaderOp1 . s:i .' TComment_gc'.s:i exec 'nmap '. g:tcommentMapLeaderOp1 . s:i .'c TComment_gc'.s:i.'c' endfor unlet s:i exec 'nmap '. g:tcommentMapLeaderOp1 .'c TComment_gcc' exec 'nmap '. g:tcommentMapLeaderOp1 .'b TComment_gcb' exec 'xmap '. g:tcommentMapLeaderOp1 .' TComment_gc' endif if g:tcommentMapLeaderUncommentAnyway != '' exec 'nmap '. g:tcommentMapLeaderUncommentAnyway .' TComment_Uncomment' exec 'nmap '. g:tcommentMapLeaderUncommentAnyway .'c TComment_Uncommentc' exec 'nmap '. g:tcommentMapLeaderUncommentAnyway .'b TComment_Uncommentb' exec 'xmap '. g:tcommentMapLeaderUncommentAnyway .' TComment_Uncomment' endif if g:tcommentMapLeaderCommentAnyway != '' exec 'nmap '. g:tcommentMapLeaderCommentAnyway .' TComment_Comment' exec 'nmap '. g:tcommentMapLeaderCommentAnyway .'c TComment_Commentc' exec 'nmap '. g:tcommentMapLeaderCommentAnyway .'b TComment_Commentb' exec 'xmap '. g:tcommentMapLeaderCommentAnyway .' TComment_Comment' endif if g:tcommentTextObjectInlineComment != '' exec 'vmap' g:tcommentTextObjectInlineComment ' TComment_ic' exec 'omap' g:tcommentTextObjectInlineComment ' TComment_ic' endif endif let &cpo = s:save_cpo unlet s:save_cpo " vi: ft=vim:tw=72:ts=4:fo=w2croql