In VS Find and Replace > Replace in Files seems to repeatedly search skipped matches before finding new matches.
Perform a Find and Replace in multiple files: File_1, File_2 and File_3
Skip one of the matches on File_1 and proceed to the next file with Find Next
Make some replacements on the next file, File_2, using Replace
After the final replacement on File_2, the Find Next match goes back to previously searched files, File_1 in this case, before going on to matches in File_3
I end up skipping through more and more previously searched files and skipped matches, just to find new matches. The Skip File option doesn't seem to help.
Is there a way to make Find/Replace search all un-searched files before looping back to the previously searched files?
I'm using VS 2012 but I seem to remember the same behavior in 2010.
Update: this is a bug. Please vote for a fix on this Visual Studio UserVoice suggestion.
I never noticed that. You can do a Find in Files, Find All. That way you have a list of all instances and can work your way down the list. Double-click the first one, press Ctrl-H, and replace or skip all matches in that file. Go back to your list and click the first match in the next file.
It will be harder to lose your place this way, but it is still tedious if you have a lot of files/matches to go through.
VS 2013 has the same behavior, in case you were curious. Sorry I don't have a better answer.
Related
Using Visual Studio 2012.
Trying to use Find in Files to find all strings in code matching a certain string.
E.g. searching for "usp_", matches would include "usp_blah", "usp_test".
Rather than displaying files wherein the matching strings occur in the Find Window 1, I want to see a list of the matching strings
Thanks
The results will show both the file and the line of code that matched
if there are multiple matches in one file there will be a line for each
filname1 ----- line 20 of code with the match line of code
filname2 ----- line 50 of code with the match line of code
i know you said you don't want a list of the files in the find window and i may be pointing out something you already know but figured i would just point that out incase you didn't see it.
i generally pull the find result out and full screen it when i am trying to review the results
I am using ctrl+shift+f to trigger "Find and replace", going to the tab "Replace in files".
I do a regexp search in the entire solution (which contains around 11000 files) for:
#layout(\d+)-top
replacing that with
#layout$1 .layout-top
A lot of files are changed by the operation, but when I after the operation open a certain css file, I still can read lines like:
#layout5-top,
#layout6-top
{
width: 960px;
height: 104px;
margin: 0 auto;
}
Why?
If I do the same search & replace with that file open, the operation will affect the file.
I can find numerous files that are not changed by the way.
In the progress indicator that comes up when the search and replace runs, I see that every file is processed, not just open files.
I hit exactly the same problem. It only seems to happen when using a regular expression. I know that the files are being matched because if I swap to just 'find in files', the correct lines are matched in the files. It seems to be a bug to me. Possibly, Microsoft don't trust us not to shoot ourselves in the foot with regexes. ;)
The only way I could resolve it was to select the option:
Replace All will open all files with changes for editing
If you don't get this warning dialog, you may have disabled it, see here.
Then just type ALTfl to save all files and close all.
This seemed to work when there were around 200 files with replacements (the full set of files searched was around 10000). I am not sure how many files Visual Studio can have open at one time, so I imagine at some point it will no longer work or replacements will be missed, in which case you may need to run it a number of times.
Is there anyway or any addin for VS2010 that can remove all the comments in the .cs file including "/// Summary" and "//"?
I don't want to do it manully foreach .cs files.
If you want it, you get it. Firstly read this http://msdn.microsoft.com/en-us/library/2k3te2cs.aspx
You exactly need expression that will match to the end of the line.
And replace it with ' ' or etc.
And then you follow this manual http://geekswithblogs.net/MarkPearl/archive/2011/04/12/vs2010-multiline-find-amp-replace.aspx
and replace all.
I'd second to Feanor. You can record a macro, like search for comment '//' and then delete that line (Ctrl+L). Edit the macro to put that in a loop. Then run this macro for each file.
If you can spend some more time in writing macro, you can loop through the Projects and ProjectItems. So that will remove comment lines from entire solution. You can learn more about EnvDTE for that.
I am refactoring a C++ codebase in Visual Studio 2005. I'm about half way through this process now and I've commented out a lot of old code and replaced or moved it. Now I'm searching to see that I have to change next but the search function keeps bringing me the old commented out stuff I no longer care about. I don't really want to delete that old code yet, just in case.
Is there any way I can search all files in the solution and get results ignoring what is commented out? I don't see a way in visual studio itself, is the perhaps a plug-in that would do it?
As the other provided solutions didn't work for me, I finally discovered the following solution:
^~(:b*//).*your_search_term
Short explanation:
^ from beginning of line
~( NOT the following
:b* any number of white spaces, followed by
// the comment start
) end of NOT
.* any character may appear before
your_search_term your search term :-)
Obviouly this will only work for // and ///-style comments.
You must click "Use Regular Expressions " Button (dot and asterisk) on your find window to apply regex search
In newer versions of visual studio .net regex is used which has a slightly different syntax:
^(?![ \t]*//).*your_search_term
My take:
yes you can use regular expressions, those tend to be too slow and thinking about them distracts from focusing on real stuff - your software.
I prefer non-obtrusive semi-inteligent methods:
Poor man's method:
Find references if you happen to use intelisense on
Or even better:
Visual assist and it's colored "Find all References" and "Go To" mapped to handy shortcuts. This speeds up navigation tremendously.
If you comment your old code with // you can use regular expressions while searching for something in your codebase. Something like this for example: ^[^/][^/].*your_function_name.*.
Previous answer gave a false-positive on cases where otherwise matching lines were placed on lines containing other source:
++i; // your_search_term gets found, don't want it found
So replaced the :b* with .* and added the <> so only entire words are found, and then went after some of the older C-style comments where there's a /* on the line:
^~(.*//)~(.*/\*).*<your_search_term>
In my case I was hunting for all instances of new, not amenable to refactor assistance, and boatloads of false-positives. I also haven't figured out how to avoid matches in quoted strings.
Just to add on, as I was doing a "find all" for division operator used in the code, used the below to exclude comments as well as </ and /> from aspx files:
^~(.*//)~(.*/\*)~(.*\<\/)~(.*/\>).*/
In Visual Basic within Visual Studio 2015, I was able to search for text outside of comments by adapting glassiko's comment from the most upvoted answer
^(?![ \t]*[']).*mysearchterm
And in C# you would use glassiko's comment exactly as it was
^(?![ \t]*//).*mysearchterm
Better use \s I think. ^(?![\s]*//).*your_search_term
delete the commented out code, it is in source control right? there is no need to keep it in the file as well.
In a solution with lots of files and projects - how would you find all completely commented files? I assume that every line of code starts with // (EDIT: or is empty) in such files.
I am using VS 2008, C#, ReSharper is available.
I know, normally such files should not exist - that's what a source safe is for ...
To find all files in and under the current directory in which all lines begin with '//':
find . -type f -exec sh -c 'grep -vq "^//" {} || echo {}' \;
Note that this will report empty files.
The argument to grep can easily be expanded to account for whitespace, or generalized to match an arbitrary regex.
There is no way to achieve this with a simple search style with the components you've mentioned. Doing this would require a bit of interpretation on the file but could be done with a fairly simple script.
It sounds like you're looking for files without code though vs. files with all comments. For example if there are 1000 lines where 900 are commented and 100 are blank, it seems to meet your criteria.
The script should be fairly straight forward to write but you would need to look out for the following weird cases
Block comments
if blocks which are always false. For example #if 0
Empty lines
Well, you could write a program (probably a console app) to recursively walk the directory and file tree. Read in all .cs files and check each line to see if its first non-space and non-tab characters are "//". If you wanted to get really fancy, you could count the total lines and the lines with "//" and display the percentages so you could catch files that didn't have absolutely every line commented out. You'll just need to understand a little bit about System.IO to get the files and string functions to look for the characters you are looking for. That should cover it.
This should be close to what you're looking for: http://www.codeproject.com/KB/cs/csharplinecounter.aspx
Look for the method in the project that determines if a line is commented or not, and you can use that to build a count, etc.