How to remove all comments in a file

If you are ever stuck in situation where you want to remove all the comments regardless of what they are in a source file. Here’s a small command that you can issue in VIM. It is for pattern search and replace using regex.

Open the file in VIM then

:g/\/\/.\+/s

Above command will look for anything after including the “//” characters which is basically a comment in C, C++, php and several other languages.

This entry was posted in Tips, linux, php. Bookmark the permalink.

Leave a Reply