• Stars
    star
    1,356
  • Rank 33,586 (Top 0.7 %)
  • Language
    Vim Script
  • License
    GNU General Publi...
  • Created almost 14 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An extensible & universal comment vim-plugin that also handles embedded filetypes
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#type#Define()| 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:tcomment_opleader1|):

    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 with count argument 
                    (see |tcomment#Comment()|)
    gcc          :: Toggle comment for the current line

Force line-wise operation:
    gC{motion}   :: Toggle comments by line
    gC<Count>c{motion} :: Toggle comment by line with count argument 
                    (see |tcomment#Comment()|)

Explicit commenting/uncommenting:

    g<{motion}   :: Uncomment region
    g<c          :: Uncomment the current line
    g<b          :: Uncomment the current region as block

    g>{motion}   :: Comment region
    g>c          :: Comment the current line
    g>b          :: Comment the current region as block

In visual mode:

    gc           :: Toggle comments
    g>           :: 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:tcomment#operator#mode_extra| to '>' (but this may not 
work properly with exclusive motions).

Primary key maps for normal and insert mode (see also |g:tcomment_mapleader1|):

    <c-_><c-_>   :: :TComment
    <c-_><space> :: :TComment <QUERY COMMENT-BEGIN ?COMMENT-END>
    <c-_>b       :: :TCommentBlock
                    In insert mode, the cursor will be positioned inside 
                    the comment. In normal mode, the cursor will stay 
                    put.
    <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)
                    In insert mode, the cursor will be positioned inside 
                    the comment. In normal mode, the cursor will stay 
                    put.
    <c-_>r       :: :TCommentRight
    <c-_>p       :: Comment the current inner paragraph
    <c-_><Count> :: Set the count argument (a number from 1 to 9) for use with 
                    the subsequent tcomment map/command (see 
                    |tcomment#Comment()|)
                    E.g. in JavaScript, in order to get an empty /** */ 
                    comment for documentation purposes, in insert mode type 
                    <c-_>2<c-_>i
                    In order to get an empty block comment like >
                      /**
                       *
                       */
<                   type <c-_>2<c-_>b

Most of the above maps are also available in visual mode.

A secondary set of key maps is defined for normal and insert mode (see also 
|g:tcomment_mapleader2|):

    <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



-----------------------------------------------------------------------
                            *tcomment-new-filetype* *tcomment-debug*
Adding a new filetype~

If tcomment doesn't know a filetype, it makes use of 'commentstring' or 
'comments'. If the result still does not satisfy your needs, you might have to 
add a custom filetype definition. This could be done in a file like 
`autoload/tcomment/types/mytypes.vim` somewhere in your 'runtimepath', which 
will be loaded on startup.

New comment types can be defined via the |tcomment#type#Define()| function. If 
the file may contain embedded code of another filetype, you might also want to 
set `g:tcomment#filetype#guess_{FILETYPE}` to 1 or the name of a default 
fallback filetype.

If nothing helps:

1. Make sure 'filetype' is set correctly.
2. Place the cursor at an appropriate position -- e.g. the first non-blank 
   character of a line of code.
3. Call |tcomment#debug#CollectInfo()|.
4. File an issue on github and post the output of `:call 
   tcomment#debug#CollectInfo()`. The output will also be copied to the 
   clipboard.

If this still doesn't help, please install tlib 
(https://github.com/tomtom/tlib_vim), please try:

    Tlibtraceset --file=tcomment.log +tcomment

Then comment out the text in question and send me the log file.


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

Either use the zip archive:

- Download the zip archive
- Extract it to `~/.vim/pack/tml/start/tcomment`

or install from github:

- Start a terminal
- Change the working directory to `~/.vim/pack/tml/start/`
- Type: `git clone https://github.com/tomtom/tcomment_vim`

NOTE: If you don't want to run this plugin on startup, use 
`~/.vim/pack/tml/opt/`.

NOTE: On Windows, ~/.vim might be ~/vimfiles. Please see 'runtimepath' for 
details.





License: GPLv3 or later


More Repositories

1

tlib_vim

Some utility functions for VIM
Vim Script
171
star
2

quickfixsigns_vim

Mark quickfix & location list items with signs
Vim Script
130
star
3

checksyntax_vim

Check a file's syntax when saving a file (php, ruby, tex ...) with vim
Vim Script
94
star
4

viki_vim

A personal wiki for Vim
Vim Script
53
star
5

tskeleton_vim

File Templates and Code Skeletons/Snippets for VIM
Vim Script
36
star
6

tinykeymap_vim

Tiny, temporary keymaps
Vim Script
33
star
7

vikitasks_vim

Search viki files for tasks and display them in a list
Vim Script
15
star
8

tplugin_vim

An on-demand runtimepath manager and plugin loader for vim (for handling plugins distributes, e.g., as git repositories)
Vim Script
15
star
9

vimform_vim

Simple text-based forms for vim
Vim Script
14
star
10

ttodo_vim

Edit, view, filter, and sort todo.txt files
Vim Script
14
star
11

enabler_vim

Obsolete repo: Load plugins/bundles
Vim Script
13
star
12

shelve

Firefox addon: filename templates to quickly save web pages
JavaScript
12
star
13

deplate

deplate is a tool for converting wiki-like markup to latex, docbook, html, or "html-slides". It supports embedded LaTeX code, footnotes, citations, biblographies, automatic generation of an index etc.
Ruby
12
star
14

tmru_vim

Most Recently Used Files in Vim
Vim Script
11
star
15

tskeletons

Templates, snippets, bits for the tskeleton vim plugin
Shell
10
star
16

likelycomplete_vim

Collect words for completion
Vim Script
9
star
17

stakeholders_vim

Pimp up your templates with charismatic, overachieving, dynamically expansive place-holders
Vim Script
9
star
18

ttags_vim

Tag list browser for VIM (List, filter, preview, jump to tags)
Vim Script
9
star
19

ttoc_vim

A regexp-based table of contents of the current buffer for vim
Vim Script
8
star
20

websitary

A ruby-based script that monitors webpages, rss feeds, podcasts etc.
Ruby
8
star
21

startup_profile_vim

Profile vim startup
Vim Script
7
star
22

templator_vim

Multi-file project templates using skeleton/snippets engines
Vim Script
7
star
23

tregisters_vim

List, edit, and run/execute registers/clipboards
Vim Script
7
star
24

spec_vim

Behaviour-driven design (BDD) for vim scripts
Vim Script
6
star
25

tbibtools_vim

Ruby-based bibtex-related utilities with optional VIM-integration (sort, reformat, list contents ...)
Ruby
6
star
26

hookcursormoved_vim

Facilitate definition of triggers on CursorMoved[I] events
Vim Script
6
star
27

trag_vim

A language-aware source code scanner (with support for git grep, ack, ag, sift ...)
Vim Script
6
star
28

tmarks_vim

Browse & manipulate marks (VIM)
Vim Script
6
star
29

workbook_vim

Interactively work with interpreteted languages (R etc.)
Vim Script
6
star
30

tcommand_vim

Select commands, menu items etc. from a list
Vim Script
5
star
31

indentfolds_vim

Indentation-level based folds with a twist
Vim Script
5
star
32

tselectbuffer_vim

A quick buffer selector/switcher for vim
Vim Script
5
star
33

vikibase_vim

A slimmed down viki plugin (a personal wiki for vim)
Vim Script
5
star
34

autolinker_vim

Automatic hyperlinks for any filetype
Vim Script
3
star
35

TortoiseSVN_vim

Use TortoiseSVN (a subversion client for Windows) from VIM
Vim Script
3
star
36

vimball.rb

A ruby script to create, install, and list the contents of vimballs
Ruby
3
star
37

vcsdo

Uniform commands for git, svn, hg repositories
3
star
38

vimtags_vim

Create and update tags files with pure VIM (without ctags etc.)
Vim Script
3
star
39

tcalc_vim

A small ruby-based RPN-calculator with optional VIM integration
Ruby
3
star
40

autopack_vim

Load optional packs/plugins by command, map, filetype etc.
Vim Script
3
star
41

prototype_vim

Simple JavaScript-like prototype-based programming in vimscript
Vim Script
3
star
42

tstatus_vim

A simple but extensible statusline manager
Vim Script
3
star
43

gdocs_vim

Edit google text documents in vim
Vim Script
3
star
44

cmdlinehelp_vim

Display help on the command currently being edited in the command line
Vim Script
3
star
45

ttagecho_vim

Show tag information for the word under cursor/mouse pointer (in VIM)
Vim Script
3
star
46

tselectfiles_vim

A quick file selector/browser/explorer (sort of) for vim
Vim Script
2
star
47

shymenu_vim

Show the menu bar in gvim only when pressing an accelerator key (or f10), and hide it again when it is no longer required
Vim Script
2
star
48

pluginstats_vim

Provide statistics how often a source file was loaded
Vim Script
2
star
49

vimtips2help.rb

Convert vimtips from wikia to vim help files
Ruby
2
star
50

vimscriptuploader.rb

Upload vim plugins to http://www.vim.org
Ruby
2
star
51

tgpg_vim

Yet another vim plugin for encrypting files with gpg
Vim Script
2
star
52

tassert_vim

Simple assertions/poor man's contracts for vim script
Vim Script
2
star
53

foldtext_vim

Fold text with headings (markdown, viki, org, latex etc.)
Vim Script
2
star
54

kindle_collections.rb

Automatically classify documents in kindle collections based on the directory structure
Ruby
2
star
55

worksheet_vim

Worksheets (Interaction with an interpreter from VIM)
Vim Script
2
star
56

tterminal_vim

Evaluate code in a terminal (with special support for R)
Vim Script
1
star
57

autoproject_vim

Set a buffer's working directory and project settings
Vim Script
1
star
58

rer_vim

Interact with R via the rescreen vim plugin
Vim Script
1
star
59

kindle_clippings.rb

Convert Kindle clippings / highlights / notes
Ruby
1
star
60

scalefont_vim

Switch between your favourite vim font/gui settings
Vim Script
1
star
61

setsyntax_vim

Set options specific for the syntax group under cursor
Vim Script
1
star
62

presets_vim

Quickly switch between vim configurations
M
1
star
63

evalselection_vim

EvalSelection -- evaluate the visual area
Vim Script
1
star
64

toptions_vim

Monitor options values in the statusline and optionally reset them to their original value
Vim Script
1
star
65

tjumps_vim

A tlib-based frontend to :jumps
Vim Script
1
star
66

rcom_vim

Evaluate R (www.r-project.org) code from GVIM via rcom, rserve, screen, or tmux
Vim Script
1
star
67

brep_vim

Scan certain buffers for a regexp and save the result as quickfix list.
Vim Script
1
star
68

linglang_vim

Dynamically switch languages/settings in multi-lingual documents
Vim Script
1
star