sponsor Vim development Vim logo Vim Book Ad

ToggleCommentify.vim : comment lines in a program

 script karma  Rating 117/53, Downloaded by 9443  Comments, bugs, improvements  Vim wiki

created by
Vincent Nijs
 
script type
utility
 
description
This is a (very) simple script to comment lines in a program. Currently supported languages are C, C++, the vim scripting language, python, and ox. Given the simplicity of the program it very easy to add support for new languages. The comments in the file should provide sufficient information on how to proceed.

 
install details
You can put the functions in the attachment directly into your .vimrc or in a separate file to be sourced. If you choose for the latter option add a statement such as ...

execute "source ~/vim/myVimFiles/ToggleCommentify.vim"

... to your .vimrc file

To call the functions add the following mappings in your .vimrc.

map <M-c> :call ToggleCommentify()<CR>j
imap <M-c> <ESC>:call ToggleCommentify()<CR>j

The nice thing about these mapping is that you don't have to select a visual block to comment ... just keep the ALT-key pressed down and tap on 'c' as often as you need.
 

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.53 2002-11-13 6.0 Robert KellyIV Incorperated Bernhard Wagner's 12-Nov-2002 v1.52 xml changes
Will make default mappings to <M-c> only if no map to <Plug>FtcTC and <M-c> is unused.
Merged DLAC with this; DLAC = duplicate line and comment, simple mappings that are handy to use to save and comment a line before you mangle it. However this mangles mark z -- <Plug>FtcDlacNormal and <Plug>FtcDlacVisual; default is <S-C-c>
Bugfix: mismatched <Plug> names; This is <Plug>FtcTc (not FbmTc)
FeralToggleCommentify.vim 1.52 2002-11-12 6.0 Bernhard Wagner Added XML file type
FeralToggleCommentify.vim 1.51 2002-11-05 6.0 Robert KellyIV *Hacked in eol comments and added html's <!-- --> comments.
* saves cursor position
* bugfix for + comment.
* See file comments for more details.
FeralToggleCommentify.vim 1.3 2002-07-21 6.0 Robert KellyIV Added :TC, :UC, :CC to toggle, uncomment and comment. Ranges suported as is specifying the comment symbol. Previous maping of <M-c> preserved (still toggles the comment)
I've made a mess but it but works quite nicely near as I can tell :) Please see the comments at the head of the file. If my changes meet your aproval I sugest renaming the file back to ToggleCommentify.vim -- only renamed it to avoid colisions and confusion. I was unable to reach Vincent via email so making my changes public here; Hope they are helpful!
ToggleCommentify.vim 1.2 2001-06-09 5.7 Vincent Nijs Resolved problems with comments.
ToggleCommentify.vim 1.1 2001-06-05 5.7 Vincent Nijs This version no longer uses 's:' (i.e., script-variables) as they are not supported in vim5.7 or vim5.8. Thanks to Rex Posadas for pointing this out to me.
ToggleCommentify.vim 1.0 2001-05-29 5.7 Vincent Nijs 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