Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 2.08
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 105 lines (78 sloc) 4.246 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
tcomment provides easy to use, file-type sensible comments for Vim. It
can handle embedded syntax.

TComment works like a toggle, i.e., it will comment out text that
contains uncommented lines, and it will remove comment markup for
already commented text (i.e. text that contains no uncommented lines).

If the file-type is properly defined, TComment will figure out which
comment string to use. Otherwise you use |tcomment#DefineType()| to
override the default choice.

TComment can properly handle an embedded syntax, e.g., ruby/python/perl
regions in vim scripts, HTML or JavaScript in php code etc.

tcomment favours the use of line-wise comment styles. This implies that usually
whole line will be commented out. tcomment also knows block-style and inline
comments that can be used via special maps (see below) or the |:TCommentAs|
command.

Demo:
http://vimsomnia.blogspot.com/2010/11/tcomment-vim-plugin.html


                                                    *tcomment-maps*
Key bindings~

Most of the time the default toggle keys will do what you want (or to be
more precise: what I think you want it to do ;-).

                                                    *tcomment-operator*
As operator (the prefix can be customized via |g:tcommentMapLeaderOp1|
and |g:tcommentMapLeaderOp2|):

    gc{motion} :: Toggle comments (for small comments within one line
                    the &filetype_inline style will be used, if
                    defined)
    gc<Count>c{motion} :: Toggle comment text with count argument
                    (see |tcomment#Comment()|)
    gcc :: Toggle comment for the current line
    gC{motion} :: Comment region
    gCc :: Comment the current line

In visual mode:

    gc :: Toggle comments
    gC :: Comment selected text

CAVEAT: If you visually select text within a line, the visual mode map will
comment out the selected text. If you selected text across several lines, the
visual mode map will assume though that you wanted to comment out lines --
since this is how many vim maps work. In order to make tcomment use e.g. inline
comments anyway, use the <c-_>i map -- see below.

By default the cursor stays put. If you want the cursor to the end of
the commented text, set |g:tcommentOpModeExtra| to '>' (but this may not
work properly with exclusive motions).

Primary key maps for normal and insert mode:

    <c-_><c-_> :: :TComment
    <c-_><space> :: :TComment <QUERY COMMENT-BEGIN ?COMMENT-END>
    <c-_>b :: :TCommentBlock
    <c-_>a :: :TCommentAs <QUERY COMMENT TYPE>
    <c-_>n :: :TCommentAs &filetype <QUERY COUNT>
    <c-_>s :: :TCommentAs &filetype_<QUERY COMMENT SUBTYPE>
    <c-_>i :: :TCommentInline (in normal and insert mode, this map will
                    create an empty inline comment, which isn't suitable for
                    all filetypes though)
    <c-_>r :: :TCommentRight
    <c-_>p :: Comment the current inner paragraph
    <c-_><Count> :: :TComment with count argument (a number from 1 to 9)
                    (see |tcomment#Comment()|)

Primary key maps for visual mode:

    <c-_><c-_> :: :TComment
    <c-_>i :: :TCommentInline
    <c-_><Count> :: :TComment with count argument (a number from 1 to 9)
                    (see |tcomment#Comment()|)

A secondary set of key maps is defined for normal and insert mode:

    <Leader>__ :: :TComment
    <Leader>_p :: Comment the current inner paragraph
    <Leader>_<space> :: :TComment <QUERY COMMENT-BEGIN ?COMMENT-END>
    <Leader>_i :: :TCommentInline
    <Leader>_r :: :TCommentRight
    <Leader>_b :: :TCommentBlock
    <Leader>_a :: :TCommentAs <QUERY COMMENT TYPE>
    <Leader>_n :: :TCommentAs &filetype <QUERY COUNT>
    <Leader>_s :: :TCommentAs &filetype_<QUERY COMMENT SUBTYPE>

... and for select mode:

    <Leader>__ :: :TComment
    <Leader>_i :: :TCommentInline


-----------------------------------------------------------------------

Status: Works for me (there may be some minor quirks)
Install: See http://github.com/tomtom/vimtlib/blob/master/INSTALL.TXT
See http://github.com/tomtom for related plugins.

Something went wrong with that request. Please try again.