" 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: 2014-06-30. " @Revision: 840 " GetLatestVimScripts: 1173 1 tcomment.vim if &cp || exists('loaded_tcomment') finish endif let loaded_tcomment = 304 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', "", ) 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_ nnoremap TComment-Uncomment :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| call tcomment#SetOption("mode_extra", "U") \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#OperatorAnywayg@ nnoremap TComment-Uncommentc :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| call tcomment#SetOption("mode_extra", "U") \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#OperatorLineAnywayg@$ nnoremap TComment-Uncommentb :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| call tcomment#SetOption("mode_extra", "UB") \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#OperatorLineg@ xnoremap TComment-Uncomment :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| call tcomment#SetOption("mode_extra", "U") \| '<,'>TCommentMaybeInline nnoremap TComment-Comment :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#OperatorAnywayg@ nnoremap TComment-Commentc :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#OperatorLineAnywayg@$ nnoremap TComment-Commentb :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| call tcomment#SetOption("mode_extra", "B") \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#OperatorLineg@ 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() nnoremap TComment-gcc :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#OperatorLineg@$ nnoremap TComment-gcb :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| let w:tcommentPos = getpos(".") \| call tcomment#SetOption("mode_extra", "B") \| set opfunc=tcomment#OperatorLineg@ xnoremap TComment-gc :TCommentMaybeInline nnoremap TComment-gc :if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| let w:tcommentPos = getpos(".") \| set opfunc=tcomment#Operatorg@ 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) exec 'nnoremap TComment-gc' . s:i .'c :let w:tcommentPos = getpos(".") \| call tcomment#SetOption("count", '. s:i .') \| set opfunc=tcomment#Operatorg@' endfor unlet s:i 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 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