sponsor Vim development Vim logo Vim Book Ad

ToggleComment : Simple, flexibel, language-independent mappings to de-/commentify

 script karma  Rating 49/22, Downloaded by 1382    Comments, bugs, improvements  Vim wiki

created by
Andreas Völter
 
script type
utility
 
description
This utility draws heavily from vimtip #271 and additional note 2002-07-06.
Yet it's different in one or more aspects from other tips and scripts I'm
aware off.

Features:

- de-/commtify lines in normal mode (with count) and visual mode
- use the same keys for commenting and decommenting
- language independent, you define different mappings for various languages
  and/or one comment-command for different filetypes
- simple and flexibel, to change the comment characters from '#' to '# ' e.g.,
  just change a mapping in your .vimrc, not the script
- comment-style: comments are indented like the uncommented line
- no hlsearch problem, last search pattern and .-command are preserved
- inserted comment characters are protected from further expansion
- might be adapted to other comment styles (first column comments, ...)

Example:

Commented text looks like this:

    #if uncommented:
        /* comment the line */
    <!-- else: -->
        // uncomment the
        // lines
        no comment

You would put or remove this comments (cursor on the first line), by typing:
    ,# ,* ,< 2,/
 
install details
Put the file ToggleComment.vim in your plugin directory or just copy/paste
the two functions in your .vimrc file.

Then define mappings in your .vimrc, like for example:

map ,# :call CommentLineToEnd('#')<CR>+
map ,* :call CommentLinePincer('/* ', ' */')<CR>+

and/or map Meta-c (Alt-c) and Meta-Shift-C for different FileTypes.

For more detailed description and installation instructions see the README file.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
ToggleComment.tar 1.6 2004-04-06 6.0 Andreas Völter Initial upload
ip used for rating: 54.81.129.89

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo