0

For commenting and uncommenting I now use the vim-commentary plugin, also the NERD commenter can be used as mentioned in: How to comment out a set of lines which are selected in visual mode?

I would like to know if there is an easy combination to change comments, for example like cic or delete the comments like dac. Note that this does not work (for as far as I could find) with the vim-commentary or NERD commenter plugins.

  • 1
    This plugin provides text objects for comments. Note that I don't use it anymore and I don't remember the reason why so it might be a bit buggy. – statox Apr 5 '16 at 12:39
4

What you are looking for is a text-object representing a comment. See :h text-objects for more information about text-objects.

By default Vim doesn't contains text-objects representing comments but the vim-textobj-comment implements this feature. Once you've got it installed you'll be able to access comments with ic and ac.

Additionally, if this plugin isn't exactly what you want it is possible to define your own text-objects (it's fun to do and a good occasion to learn new stuff). To do so you can have a look here.

  • 1
    Commentary.vim also provides the gc text object. e.g. dgc – Peter Rincker Apr 5 '16 at 14:30
  • @PeterRincker: I've never used Commentary.vim but from reading the readme I'm not sure gc is the same thing: is it possible for example to do something like vgc to visually select the content of a comment? – statox Apr 5 '16 at 14:33
  • Commentary.vim does not provide a visual mode mapping for gc. It only provides an operator pending mode mapping. I pretty much only use if for toggling a comment block via: gcgc – Peter Rincker Apr 5 '16 at 14:36
  • 1
    That sounds pretty useful. Actually I created this answer because I suggested vim-textobj-comment in the comments of the question and OP said it was what he wanted but maybe you should also add an answer with commentary.vim if it fills the needs of the question. – statox Apr 5 '16 at 14:39
2

Commentary.vim provides the gc text object for comments. You can use dgc for example to delete a comment block. I find that my most common usage is gcgc to uncomment a comment block.

Note: Commentary.vim does not provide a visual mode mapping for a comment text object. Meaning you can not do vgc.

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.