Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Vim have an auto-comment feature based on the file's syntax?

I'm not sure this is possible, but I'm interesting in making this happen.
Ideally, I would like to map this feature to SHIFT+CTRL+3.

I'm looking for a way to have Vim enter a comment (single line) which corresponds to the syntax of the file I'm editing. If there are multiple single-line comment styles, Vim could either automatically pick one, or give me the choice. If the single-line comment has two parts (e.g. /* and */), then pressing SHIFT+CTRL+3 the first time will start the comment, and the second time will close the comment.

Examples:

  • Python: #
  • JavaScript: //
  • C, C++: /* with */ or //

I know there are scripts which will insert comments for you, but I haven't seen any that will do this based on the syntax of the file.

like image 881
Nick Presta Avatar asked Jun 30 '09 14:06

Nick Presta


1 Answers

I highly recommend NERD Commenter.

like image 145
Jeremy Cantrell Avatar answered Oct 21 '22 23:10

Jeremy Cantrell