Skip to content


Subversion checkout URL

You can clone with
Download ZIP
commentary.vim: comment stuff out
Branch: master

Use setlocal in the filetype example

Using local is problematic with multiple buffers/windows, e.g.:

- You have the auto-command configured for cmake files, where the
  comment string is set to '#'
- You split your main window into 2 side-by-side ones
- In the left window you open a C++ file
- In the right window you open a cmake file
- voila, the wrong comment string is then used when commenting out stuff
  with commentary commands in the left window
latest commit 7fb632aab4
@gsauthof gsauthof authored committed



Comment stuff out. Use gcc to comment out a line (takes a count), gc to comment out the target of a motion (for example, gcap to comment out a paragraph), gc in visual mode to comment out the selection, and gc in operator pending mode to target a comment. You can also use it as a command, either with a range like :7,17Commentary, or as part of a :global invocation like with :g/TODO/Commentary. That's it.

I wrote this because 5 years after Vim added support for mapping an operator, I still couldn't find a commenting plugin that leveraged that feature (I overlooked tcomment.vim). Striving for minimalism, it weighs in at under 100 lines of code.

Oh, and it uncomments, too. The above maps actually toggle, and gcgc uncomments a set of adjacent commented lines.


If you don't have a preferred installation method, I recommend installing pathogen.vim, and then simply copy and paste:

cd ~/.vim/bundle
git clone git://

Once help tags have been generated, you can view the manual with :help commentary.


My favorite file type isn't supported!

Relax! You just have to adjust 'commentstring':

autocmd FileType apache setlocal commentstring=#\ %s


Like commentary.vim? Follow the repository on GitHub and vote for it on And if you're feeling especially charitable, follow tpope on Twitter and GitHub.


Copyright (c) Tim Pope. Distributed under the same terms as Vim itself. See :help license.

Something went wrong with that request. Please try again.