Find & replace in visual studio not replacing all occurrences - visual-studio

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.

Related

Simplifying Visual Studio Find result format

I want to simplify Visual Studio Find in Files result, and I found a posting.
And I found it is not quite satisfactory.
Is there a way to display partial portion of directory in find result window?
ie)
x:\users\myname\project\solution_home\project1_home\src\project1.cpp
x:\users\myname\project\solution_home\project1_home\src\helper.cpp
x:\users\myname\project\solution_home\project2_home\src\helper.cpp
into
\project1_home\project1.cpp
\project1_home\helper.cpp
\project2_home\helper.cpp
IMHO, filename alone is not enough to distinguish important result, particulary in large soultion.
but, I want to eliminate certain part of directory path being repeated in every single result.
I wish there would be directory depth designation in $d format string.
ie)
$0d : file's directory
$1d : parent directory
$2d : parent of parent
... etc
Is there any extension and/or technique to do this?
PS: sorry for my poor english
I have something of a hack for this problem: map the local path to a drive. For example:
> subst Y: x:\users\myname\project\solution_home
Your Find Results will then be:
Y:\project1_home\project1.cpp
Y:\project1_home\helper.cpp
Y:\project2_home\helper.cpp
N.B. It has the side effect of breaking the CodeLens Team indicators (which must be a bug).

How to browse for file (Win7/64bits)

I need to quickly write a simple GUI over a command line application. Two steps are required:
Specify an input file path,
Specify an output file path (non existing)
I found out a previous post, however trying to get the above (1) to work seems like an insane task.
Indeed BrowseForFolder seems to only work in some weird cases, you can use BIF_BROWSEINCLUDEFILES for only *.pdf and/or *.txt (trial and errors). I can get an error if I select a *.dll and/or a *.jpg (don't ask).
So instead, I gave up this approach and followed another one, in this case (objIE.Document.all.FileSelect), only the name of the selected file is returned the path seems to be always set to "c:/fakepath" for some reason. So again I am missing the full path to be able to pass that to the command line app.
Is there any sane way (<10 lines of codes) to get (1) and (2) working on Win7/64bits (VBS, HTA...)?
Don't know if people are still interested in the BrowseForFolder file selection issue, but here's what I've found.
I had the same issue selecting files with BrowseForFolder using &H4000 / BIF_BROWSEINCLUDEFILES. I could get a return with .docx but not .doc files and as you say .pdf files.
For me .txt wouldn't return anything, as didn't WMI Backup .rec files that I needed for a script I'm writing, resulting in this error information:-
Error: Unspecified error
Code: 80004005
Source: (null)
After looking at other solutions I came back to this one as my preferred choice, plus it was doing my head in that it didn't want to work. So at the bitter end it seems to be this easy.
To get my .rec files recognized I add this to the registry:-
[HKEY_CLASSES_ROOT\.rec]
#="WMI.Backup"
[HKEY_CLASSES_ROOT\WMI.Backup]
#="WMI Backup"
"BrowseInPlace"="1"
To get .txt files recognized I add this to the registry:-
[HKEY_CLASSES_ROOT\txtfile]
"BrowseInPlace"="1"
So "BrowseInPlace"="1" seems to be the nugget.
Seems so unbelievably easy that I'm sure this solution is out there somewhere but I never came across it so thought I'd put it online.
I would be interested to find that it works for others as I fear that this issue may of sent me mad, still can't believe it seems to work.
Hope this helps.
Here are 3 different ways to do what you want:
http://www.robvanderwoude.com/vbstech_ui_fileopen.php

Visual Studio Replace in Files Searches Skipped Matches After Each Replace

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.

visual studio able to save state for multiple indivisual files not in solutions?

Often I use Visual studio to edit standalone files (not in a project). So usually I will have like say 6 files opened (3 html files, 1 css file, 2 js files etc)
And the problem is that whenever i close visual studio, I have to locate and re-open all 7 files again (which is a bother really).
Is there a way for us to like save all 7 files in a state file and simply when i open that state file it will open all the 7 files in whatever order I have last saved them as ?
If you have used Notepad++ you will know what I'm talking about, basically when we close Notepad++ and open it the files that were previously opened stay opened, some sort of functionality like this.
Here's two Visual Studio macro methods that should do exactly what you need.
SaveAll() saves all open files and writes a file named status.txt to C: in which all open files are written separated by semicolon (totally independent of project/solution):
Sub SaveAll()
Dim text As String
Dim i As Integer
For i = 1 To DTE.Documents.Count
text += DTE.Documents.Item(i).FullName + ";"
DTE.Documents.Item(i).Save()
Next i
My.Computer.FileSystem.WriteAllText("C:\status.txt", text, False)
End Sub
Next time, when you want to open those files, you simply call OpenAll(). It reads the status file, splits the semicolon separated text, and opens all files:
Sub OpenAll()
'Open status file
Dim text As String
text = My.Computer.FileSystem.ReadAllText("C:\status.txt")
Dim files As String()
files = text.Split(";")
Dim file As String
For Each file In files
If file.Length > 0 Then DTE.ItemOperations.OpenFile(file)
Next
End Sub
It's easy enough to modify this according to your needs (or even add a file dialogue). Thanks for asking this question, it made me focus on the VS macro IDE again and see how powerful it is.
You could just have a temporary or scratch solution for adding these files to, and when you've finished working on them (after days or weeks or whatever) just remove them. Solution files are probably a bit much for this, but you wouldn't have to do any extra work.
Otherwise look at making the recently opened files list a bit longer so they stay in there for longer.
Or use another editor for this purpose. I use Notepad++ for all my non-solution/non-project related files. If you close it without closing the individual files they remain in the editor next time you open it. It's faster and lighter weight than VS too.

Visual Studio 2010 SP1 does not search for text in *.*

I used to be able to search for a text in every file in solution, like that: http://vvcap.net/db/lWMPaSHxormUrFYlLo0Q.htp . After upgrading to VS2010 SP1, this doesn't work anymore:
Find all "description", Match case, Whole word, Subfolders, Keep modified files open, Find Results 1, "Entire Solution", "*.*"
No files were found to look in.
Find was stopped in progress.
What's interesting, I can still search if I know file extension, like this: http://vvcap.net/db/IFr8jCUa7J79sauBsNFC.htp :
Find all "description", Match case, Whole word, Subfolders, Keep modified files open, Find Results 1, "Entire Solution", "*.cs"
...
...
Matching lines: 485 Matching files: 109 Total files searched: 970
Anyone knows wtf is going on here, and how to get around this?
I don't know what happened, but now my VS is searching for "*" again. Maybe after last windows update... I have no reasonable explanation as to wtf happened
It's a known bug. You can get the visual studio search results to appear by using CTRL + Break in the Find Results window

Resources