Replacing multi-line text in Visual Studio solutions
I was editing a Visual C++ project of Flight Sim Labs recently and came across conditional defines of the following form at many of their C++ header files:
#if _MSC_VER > 1000
That would be obviously faster to parse (taking in mind that the solution had a big number of C++ header files) and would result in less noise to anyone reading that source code to understand it and work with it, if it was converted to a simpler form:
Having less clutter at the top of a source code file frees the programmer from having to scroll down a lot after opening the file to examine or work with it.
Having a big number of header files though meant that I had to find some way to replace all that automatically through out the solution. So I used the powerful "Replace in Files" action from Visual Studio’s Edit menu, using the intuitive "Wildcards" mode with the settings shown at the side-image. Note the \# and \n to escape the special # char and to define line change respectively.
Could also have used "Regular Expression" mode, but would need a different and a bit non-intuitive syntax for the search string (but this is more a matter of taste I guess).
To avoid having lots of open file tabs after the "Replace All" operation, I unchecked the option "Keep modified files open after Replace All". This results in the IDE doing the replace and saving the changed file without keeping the file open in a "dirty" state for you to save.