summaryrefslogtreecommitdiffstats
path: root/vim/doc/tcomment.txt
blob: c0c0f17e336e976aaf7d0fb384e5570040ebb253 (plain) (blame)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
*tcomment.txt*  An easily extensible & universal comment plugin
                Author: Thomas Link, micathom AT gmail com?subject=vim

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.

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 ;-).

                                                    *g:tcommentMapLeaderOp1*
                                                    *g:tcommentMapLeaderOp2*
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)
    gcc          :: Toggle comment for the current line
    gC{motion}   :: Comment region
    gCc          :: Comment the current line

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:

    <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
    <c-_>r       :: :TCommentRight
    <c-_>p       :: Comment the current inner paragraph

A secondary set of key maps is defined for normal 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>


-----------------------------------------------------------------------
Install~

Edit the vba file and type: >

    :so %

See :help vimball for details. If you have difficulties or use vim 7.0, 
please make sure, you have the current version of vimball (vimscript 
#1502) installed or update your runtime.


========================================================================
Contents~

        :TComment ........................... |:TComment|
        :TCommentAs ......................... |:TCommentAs|
        :TCommentRight ...................... |:TCommentRight|
        :TCommentBlock ...................... |:TCommentBlock|
        :TCommentInline ..................... |:TCommentInline|
        :TCommentMaybeInline ................ |:TCommentMaybeInline|
        g:tcommentBlankLines ................ |g:tcommentBlankLines|
        g:tcommentOpModeExtra ............... |g:tcommentOpModeExtra|
        g:tcommentOptions ................... |g:tcommentOptions|
        g:tcommentGuessFileType ............. |g:tcommentGuessFileType|
        g:tcommentGuessFileType_dsl ......... |g:tcommentGuessFileType_dsl|
        g:tcommentGuessFileType_php ......... |g:tcommentGuessFileType_php|
        g:tcommentGuessFileType_html ........ |g:tcommentGuessFileType_html|
        g:tcommentGuessFileType_tskeleton ... |g:tcommentGuessFileType_tskeleton|
        g:tcommentGuessFileType_vim ......... |g:tcommentGuessFileType_vim|
        g:tcommentGuessFileType_django ...... |g:tcommentGuessFileType_django|
        g:tcommentIgnoreTypes_php ........... |g:tcommentIgnoreTypes_php|
        g:tcomment#syntax_substitute ........ |g:tcomment#syntax_substitute|
        g:tcommentSyntaxMap ................. |g:tcommentSyntaxMap|
        g:tcommentBlockC .................... |g:tcommentBlockC|
        g:tcommentBlockC2 ................... |g:tcommentBlockC2|
        g:tcommentInlineC ................... |g:tcommentInlineC|
        g:tcommentBlockXML .................. |g:tcommentBlockXML|
        g:tcommentInlineXML ................. |g:tcommentInlineXML|
        tcomment#DefineType ................. |tcomment#DefineType()|
        tcomment#Comment .................... |tcomment#Comment()|
        tcomment#Operator ................... |tcomment#Operator()|
        tcomment#OperatorLine ............... |tcomment#OperatorLine()|
        tcomment#OperatorAnyway ............. |tcomment#OperatorAnyway()|
        tcomment#OperatorLineAnyway ......... |tcomment#OperatorLineAnyway()|
        tcomment#CommentAs .................. |tcomment#CommentAs()|


========================================================================
plugin/tcomment.vim~

                                                    *:TComment*
:[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

                                                    *:TCommentAs*
:[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

                                                    *:TCommentRight*
:[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

                                                    *:TCommentBlock*
:[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

                                                    *:TCommentInline*
:[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

                                                    *:TCommentMaybeInline*
:[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


========================================================================
autoload/tcomment.vim~

                                                    *g:tcommentBlankLines*
g:tcommentBlankLines           (default: 1)
    If true, comment blank lines too

                                                    *g:tcommentOpModeExtra*
g:tcommentOpModeExtra          (default: '')
    Modifies how the operator works.
      > ... Move the cursor to the end of the comment

                                                    *g:tcommentOptions*
g:tcommentOptions              (default: {})
    Other key-value options used by |tcomment#Comment()|.
    
    Example: If you want to put the opening comment marker always in 
    the first column regardless of the block's indentation, put this 
    into your |vimrc| file: >
      let g:tcommentOptions = {'col': 1}
<

                                                    *g:tcommentGuessFileType*
g:tcommentGuessFileType        (default: 0)
    Guess the file type based on syntax names always or for some fileformat only
    If non-zero, try to guess filetypes.
    tcomment also checks g:tcommentGuessFileType_{&filetype} for 
    filetype specific values.
    
    Values:
      0        ... don't guess
      1        ... guess
      FILETYPE ... assume this filetype

                                                    *g:tcommentGuessFileType_dsl*
g:tcommentGuessFileType_dsl    (default: 'xml')
    For dsl documents, assumet filetype = xml.

                                                    *g:tcommentGuessFileType_php*
g:tcommentGuessFileType_php    (default: 'html')
    In php documents, the php part is usually marked as phpRegion. We 
    thus assume that the buffers default comment style isn't php but 
    html.

                                                    *g:tcommentGuessFileType_html*
g:tcommentGuessFileType_html   (default: 1)

                                                    *g:tcommentGuessFileType_tskeleton*
g:tcommentGuessFileType_tskeleton (default: 1)

                                                    *g:tcommentGuessFileType_vim*
g:tcommentGuessFileType_vim    (default: 1)

                                                    *g:tcommentGuessFileType_django*
g:tcommentGuessFileType_django (default: 1)

                                                    *g:tcommentIgnoreTypes_php*
g:tcommentIgnoreTypes_php      (default: 'sql')
    In php files, some syntax regions are wongly highlighted as sql 
    markup. We thus ignore sql syntax when guessing the filetype in 
    php files.

                                                    *g:tcomment#syntax_substitute*
g:tcomment#syntax_substitute   (default: {...})

                                                    *g:tcommentSyntaxMap*
g:tcommentSyntaxMap            (default: {...})
    tcomment guesses filetypes based on the name of the current syntax 
    region. This works well if the syntax names match 
    /filetypeSomeName/. Other syntax names have to be explicitly 
    mapped onto the corresponding filetype.

                                                    *g:tcommentBlockC*
g:tcommentBlockC               (default: {...})
    Generic c-like block comments.

                                                    *g:tcommentBlockC2*
g:tcommentBlockC2              (default: {...})
    Generic c-like block comments (alternative markup).

                                                    *g:tcommentInlineC*
g:tcommentInlineC              (default: "/* %s */")
    Generic c-like comments.

                                                    *g:tcommentBlockXML*
g:tcommentBlockXML             (default: "<!--%s-->\n  ")
    Generic xml-like block comments.

                                                    *g:tcommentInlineXML*
g:tcommentInlineXML            (default: "<!-- %s -->")
    Generic xml-like comments.

                                                    *tcomment#DefineType()*
tcomment#DefineType(name, commentdef)
    If you don't explicitly define a comment style, |:TComment| will use 
    'commentstring' instead. We override the default values here in order 
    to have a blank after the comment marker. Block comments work only if 
    we explicitly define the markup.
    
    The comment definition can be either a string or a dictionary.
    
    If it is a string:
    The format for block comments is similar to 'commentstrings' with the 
    exception that the format strings for blocks can contain a second line 
    that defines how "middle lines" (see :h format-comments) should be 
    displayed.
    
    If it is a dictionary:
    See the help on the args argument of |tcomment#Comment|.

                                                    *tcomment#Comment()*
tcomment#Comment(beg, end, ...)
    tcomment#Comment(line1, line2, ?commentMode, ?commentAnyway, ?args...)
    args... are either:
      1. a list of key=value pairs where known keys are (see also 
         |g:tcommentOptions|):
            as=STRING     ... Use a specific comment definition
            col=N         ... Start the comment at column N (in block mode; must 
                              be smaller than |indent()|)
            mode=STRING   ... See the notes below on the "commentMode" argument
            begin=STRING  ... Comment prefix
            end=STRING    ... Comment postfix
            middle=STRING ... Middle line comments in block mode
            rxbeg=N       ... Regexp to find the substring of "begin" that 
                              should be multipied by "count"
            rxend=N       ... The above for "end"
            rxmid=N       ... The above for "middle"
      2. 1-2 values for: ?commentPrefix, ?commentPostfix
      3. a dictionary (internal use only)
    
    commentMode:
      G ... guess the value of commentMode
      B ... block (use extra lines for the comment markers)
      i ... maybe inline, guess
      I ... inline
      R ... right (comment the line right of the cursor)
      v ... visual
      o ... operator
    By default, each line in range will be commented by adding the comment 
    prefix and postfix.

                                                    *tcomment#Operator()*
tcomment#Operator(type, ...)

                                                    *tcomment#OperatorLine()*
tcomment#OperatorLine(type)

                                                    *tcomment#OperatorAnyway()*
tcomment#OperatorAnyway(type)

                                                    *tcomment#OperatorLineAnyway()*
tcomment#OperatorLineAnyway(type)

                                                    *tcomment#CommentAs()*
tcomment#CommentAs(beg, end, commentAnyway, filetype, ?args...)
    Where args is either:
      1. A count NUMBER
      2. An args list (see the notes on the "args" argument of 
         |tcomment#Comment()|)
    comment text as if it were of a specific filetype



vim:tw=78:fo=tcq2:isk=!-~,^*,^|,^":ts=8:ft=help:norl: