I want to delete all the comments from a program. Vim already knows (in some sense) where all the comments are because it is correctly formatting them based on the syntax file the particular language I'm using. So, I'd like to do something like this:




I think that the SrchRplcHiGrp.vim plugin might be what you're looking for.

You can install it with your favorite method. For example with Vundle just put this line in your .vimrc:

Plugin 'vim-scripts/SrchRplcHiGrp.vim'

You can select the highlighting group you want to work with by placing your cursor on the comment and running :SRChooseHiGrp.

Then you can use :SRHiGrp to replace the members of the higlighting group.

You'll find the documentation on the page linked at the beggining of my answer.

| improve this answer | |
  • I was hoping to avoid a plugin, but if no other answers appear in the next several hours, I'll mark this one as accepted. Thanks! – Jeff Jun 12 '15 at 18:35
  • 1
    @Jeff I can understand that you don't want plug-ins but I think that for doing what you want that's the best way to save you a lot of vimscript work. I hope a vim master will provide you a better solution. ;) – statox Jun 12 '15 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.