sponsor Vim development Vim logo Vim Book Ad

toggle_comment : To Toggle Comment of single/multiple lines of code

 script karma  Rating 14/7, Downloaded by 1202    Comments, bugs, improvements  Vim wiki

created by
farid smai
script type
A small plugin to comment, un-comment or toggle one or more lines in both normal and visual mode.

** Usage **
In normal or visual mode:
    q to toggle comment
    shift-q to force comment
    alt-q to force un-comment

Also avaible in command mode:
    Ct to toggle comment
    Cc to force comment
    Cu to force un-comment
These 3 commands are compatible with range and global (:g)

** Examples **
'yyqp' : duplicate and comment an uncommented line
'vjq' : when two lines are [1 commented/1 un-commented], switch the state of each line
':g!/toto/Cc' : comment all lines which not contain 'toto'

** Remarks **
- The plugin will check the option "&filetype" and the variable "b:current_syntax" to know how to comment the file.
- "echo &filetype" or "echo b:current_syntax" will give you the name of the syntax of the opened file.
- Add a new syntax to the script (or change the default behavior) is very very simple (add only one line), so don't hesitate to adapt the script.
-  For languages like fortran where the rest of the line should not be disturbed by the comment symbol, don't forget to add a line to "s:comment_in_place".
install details
copy script to ~/.vim/plugin

I am not sure but, since instructions in the script are quite simple, I think that this plugin must be compatible with older vim versions.

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
toggle_comment.vim 1.7 2013-02-12 7.0 farid smai fix bug with c-style comments : last search was replaced by a dummy search ; now last search is preserved.
toggle_comment.vim 1.6 2012-02-13 7.0 farid smai - fix bugs due to some comment symbols that end with one or more sapce ('\s')
toggle_comment.vim 1.5 2012-02-13 7.0 farid smai - improve the mechanism to find the "comment symbol". Now, we also use the "&comments" and "&commentstring" options if the "comment symbol" is not defined internarly.
toggle_comment.vim 1.3 2012-01-31 7.0 farid smai - add command compatible with range
- change to make command compatible with ':g'
- change map because ctrl-q is not compatible with terminal
toggle_comment.vim 1.2 2012-01-30 7.0 farid smai fix big trouble on some OS
ip used for rating:

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