sponsor Vim development Vim logo Vim Book Ad

commentop.vim : commands and operators to comment/uncomment lines in many languages

 script karma  Rating 9/7, Downloaded by 2014  Comments, bugs, improvements  Vim wiki

created by
Takahiro SUZUKI
script type

  This plugin provides a set of commands and operators  to comment or
  uncomment lines. Linewise comment token (such as double quote in vim
  script) is detected automatically by looking up filetype of the file.
  Filetypes working well by default:
    vim, python, perl, ruby, haskell, sh, bash, zsh, java, javascript,
    Makefile, tex
  With definition in this script, these also work:
    (c), cpp, csharp, php, matlab

  You can also easily define your own comment token for filetype. Add below
  in your .vimrc:

  plugin keymaps:
    <Plug>CommentopToggleNV    " (n/v) toggle comment [count] or visual lines
    <Plug>CommentopAppendNV    " (n/v) comment out [count] or visual lines
    <Plug>CommentopRemoveNV    " (n/v) uncomment [count] or visual lines

    <Plug>CommentopToggleOP    " (n op) toggle comment {motion}
    <Plug>CommentopAppendOP    " (n op) comment out {motion}
    <Plug>CommentopRemoveOP    " (n op) uncomment {motion}

  default mapping:
    co       <Plug>CommentopToggleNV
    cO       <Plug>CommentopAppendNV
    c<C-O>   <Plug>CommentopRemoveNV

    go       <Plug>CommentopToggleOP
    gO       <Plug>CommentopAppendOP
    g<C-O>   <Plug>CommentopRemoveOP

  in normal mode:
     co          " toggle comment for this line
     3cO         " comment out 3 lines

  in normal mode (operator):
     goip        " toggle comment for this paragraph
     gOa{        " comment out this {} block

  in visual mode:
     c<C-O>      " remove comments in visual selection
install details
Place this file in /usr/share/vim/vim*/plugin or ~/.vim/plugin/

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
commentop.vim 1.1.1 2009-07-26 7.0 Takahiro SUZUKI simplified the script using range function.
counting WS with virtcol (work fine with mixture of tabs and spaces).
commentop.vim 1.1.0 2009-07-12 7.0 Takahiro SUZUKI simplified <Plug> maps (no backward compatibility for 1.0.2 or before)
determine the comment string automatically (using 'commentstring')
commentop.vim 1.0.2 2009-07-11 7.0 Takahiro SUZUKI bug fix (wrong comment string with ft=vim)
commentop.vim 1.0.1 2009-07-09 7.0 Takahiro SUZUKI bug fix (gO was mapped to comment out operator)
commentop.vim 1.0 2009-07-08 7.0 Takahiro SUZUKI Initial upload
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.