sponsor Vim development Vim logo Vim Book Ad

FeralToggleCommentify.vim : My fork of ToggleCommentify.vim; comment lines in a program

 script karma  Rating 91/36, Downloaded by 5003  Comments, bugs, improvements  Vim wiki

created by
Robert KellyIV
 
script type
utility
 
description
This script offers simple, basic, line oriented commenting of files.
Originally vimscript #4 (ToggleCommentify.vim v1.2 ) by Vincent Nijs
Was mutilated into what you see here, for better or worse :)

Following list of file types are currently (v1.55) supported:
    ox, cpp, php, java, bnk, cs, ftf, torquescript, fte, html, xml, c, css,
    pov, vim, lisp, scheme, dosini, tex, caos, m4, config, automake, python,
    perl, make, [^w]sh$, tcl, jproperties, vb, aspvbs, plsql, lua,


Three commands:
:CC        " To Comment a line/range
:UC        " To Uncomment a line/range
:TC        " To Toggle comments on each line/range.

All take optional arg to override default comment style
i.e. ":CC --"

Maps <m-c> to :TC if no command by that name already exists. Remap <Plug>FtcTc
    at will.
Maps <C-c> to a duplicate and comment, line/range; so you can easily make a
    duplicate of the current line/range and comment it; then edit it the
    original. Remap <Plug>FtcDLAC at will.

**********
New with v1.55:
You can customize the behavior by specifying optional option vars. Each option
var can be specified as buffer or global, with that precedence.

Option: g:FTCOperateOnFirstColumnOnly
    If this is 0 (false) then the comment char does not have to be at col1 to
    be removed, in addition comment chars are placed just before the first word
    of the line.
Valid Values: 0 or 1
Default: 1

Option: g:FTCOperateOnlyOnNonComments
    If 1 (true) a line will not be commented if it already starts with comment
    chars. With this 0 (false) you can (easily) comment entire functions
    without fear of messing up commenting (i.e. '<,'>CC ... '<,'>UC ...  I.e.
    comment then uncomment. If this is true the above MAY not work (depending
    on how the existing comments are.)
Valid Values: 0 or 1
Default: 0

Option: g:FTCOperateOnBlankLines
    If 1 (true) blank lines will be processed, else they are skipped.
Valid Values: 0 or 1
Default: 1

Option: g:FTCBangEffectsWhat
    Will toggle an option if command is banged: (i.e. :CC!)
        1. OperateOnFirstColumnOnly
        2. OperateOnlyOnNonComments
        3. OperateOnBlankLines
Valid Values: 1, 2 or 3
Default: 1


I.e. in .vimrc:
let g:FTCOperateOnFirstColumnOnly = 0
let g:FTCOperateOnlyOnNonComments = 1
 
install details
Just drop in plugins/
 

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
feraltogglecommentify.vim 1.611 2005-04-28 6.0 Robert KellyIV 1.61 - Improved/Fixed cursor restore. Screen should not jump; ever.
1.611 - bugfix for above for column jumping about, *sigh*.
feraltogglecommentify.vim 1.58 2003-08-28 6.0 Robert KellyIV Added rebol ';' comment type, contribution by Tim Johnson
feraltogglecommentify.vim 1.57 2003-08-19 6.0 Robert KellyIV Added ruby '#' comment type, contribution by Brett Williams
Added sh '#' comment type.
feraltogglecommentify.vim 1.56 2003-07-21 6.0 Robert KellyIV BUG FIX: Fixed silly cursor restore problem, screen no longer jumps on occasion.
feraltogglecommentify.vim 1.55 2003-07-16 6.0 Robert KellyIV Integrating changes from Jörn Horstmann. Changes are marked with "JH:".
Improvement:    Added options to determine how this should react.
* Optionally does not mess with blank lines.
* Change by JH, comment does not have to be in first column
* Change by JH, only add comment when not already commented
Please see "Customizing:" (in the script file) for details and usage:
feraltogglecommentify.vim 1.54 2003-07-12 6.0 Robert KellyIV 2 BUG FIXes, 2 Improvements:
* BUG FIX: (minor) no longer complains when uncommenting and there are no comment char(s). (aka middle of a range is uncommented already)
* BUG FIX: Respects 'hlsearch'; won't mess with highlighting if off, etc. (Previous turned it on at end of script)
* Improvement: Can now comment/uncomment a fold without opening it.  (courtesy of normal! zn and normal! zN)
* Improvement: Changed DLAC into a proper command (:DLAC) (from mapping); map <Plug>FtcDLAC as desired, defaults to <C-c>. Ranges are supported (default current line) and you can specify the comment chars just as you can with :CC, :TC, :UC.
FeralToggleCommentify.vim 1.532 2003-06-04 6.0 Robert KellyIV Initial upload
ip used for rating: 142.132.191.50

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.
   
Vim at Github