The Find dialog (Ctrl+F) does not allow multi-line finds using the \n
character as it currently considers each line individually. See TextModel._doFindMatches
_Created out of a discussion in https://github.com/Microsoft/vscode/issues/278_
Indeed, the find is executed on a line by line basis. To implement multi-line search we need to do the following:
It is a little bit of work to get all of this done.
:+1: (commenting to get updates on this)
@sushruth FYI there is a "Subscribe" button to the right on github that lets you follow the thread without commenting.
I got the newest update today, and I still suffer from this.
I almost always use multi line regex, and this is the only feature that's keeping me away from daily usage.
So +1.
+1
Unfortunately it's a common omission from text editors, presumably due to simplicity of line-based text representation / search model. But nevertheless it's a very useful feature for day-to-day work.
Please please fix!
馃憤 I would love this feature as well.
+10086
This can be very useful. +++. hope we can have this soon!
Come on people. Subscribe. Stop spamming. Will not help comment on this.
Tired of copying code from VSCode to VS or SSMS only to make some regex multiline replaces.
Do you have any estimate time on this @Tyriar @alexandrudima?
How long until a solution for this?
+1
I install Sublime Text because of this issue.
Isn't there a typo in the issue text?
The Find dialog (Ctrl+F) does allow multi-line finds
should be
The Find dialog (Ctrl+F) does not allow multi-line finds
@shakvaal fixed :smiley:
@Tyriar Thank you! It was extremely confusing before the fix :)
This should now be straight-forward to implement as I've added offset <-> position conversion in the IModel.
I go back and forth now between Visual Studio 2015 and Visual Studio Code because of this one issue of not being able to find line-breaks and replacing them. Any potential upcoming fixes for this?
@blachawk Try Notepad++ - as a hyperfast application it's much more suitable as a regex evaluator than VS2015 is)
:tada:
I see the issue is closed, I see you have unit tests, but I still can't get this to work. In any other editor, replacing ^\s*$\n
with an empty string removes all empty lines. However, it doesn't work i VS code. \n
matches on newline, so that doesn't seem to be the problem. Have you really verifies in the actual editor that this works after the jun release?
@erikbra We are not massaging ^
or $
in the context of multiline searches. So the default JavaScript regex semantics apply to them (which is the beginning of the string, the end of the string) and not the beginning of the line, the end of the line that you probably expect. You can workaround for for example by searching for \n\s*\n
and replacing with \n
. Please feel free to open a separate issue, but given we don't implement our own regex engine and simply use the one in JavaScript, I am not sure how this can ever be fixed to work as you would expect (^
= line start, $
= line end).
I understand where you are coming from, but, if I were to be a bastard, I could claim that the language with which you implement a text editor should not dictate the behaviour of the editor...
\n\s*\n
is OK, but it doesn't work for the first and last lines of the file. And, this is just a special case. Say I want to remove/massage lines that look like
A*************************************B
this is impossible without being able to match on the beginning and end of a line.
^A.*B$
matches this in just about every decent editor except VS code. Should I open a separate issue, you think?
@erikbra :smile: Yes, please go ahead and create a new issue.
There might be a low-hanging fix. Maybe we're not setting the multiline flag:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
Looking great, @alexandrudima, if this could fix it. See new issue #11572.
I'm unable to get this to match
Running this on regex101 seems to work fine
Another question is if VS Code's regex search supports inline flags like Sublime ie (single line, . matches new line): (?s)<fieldset>.*<legend>
In this example this is useful for finding a legend tag after or possibly within a fieldset tag, whether or not it's on the next line from fieldset.
@g5codyswartz nice find, I created https://github.com/Microsoft/vscode/issues/13369
Not sure about inline flags.
Is this fixed? Still can't do multiline regex on VS Code 1.9.1, Mac
what was the resolution to this issue?
@joeshub, you should be able to match against newlines now with \s
... I'm also able to match more explicitly with \r?\n
(CR is for potentially crlf/windows line endings). It's working for me in the most recent march 2017 release (1.11.2).
@tracker1 I see thank you. this works but only for open files in VS Code. Please tell me I don't have to open every file in my project before searching w/ regex :)
Yeah that behavior (where "find in files" only returns results in _open_ buffers) is misleading at best. Nothing even warns you that it's occurring.
Why is this closed? Multiline regex find and replace does not work in 1.13.1. Looks like it finds only in opened buffers, but how useful is that?
In case anyone is still struggling with this.
The workaround for doing something like a negative lookbehind assertion using mult-lines. You can do something like.
(?
This is searching for the string "config." (no double quotes) that is not proceeded by "configService'" (no double quotes) and any/all characters with multiple lines in between.
As an aside, I stopped logging bugs against Microsoft products because they'll never fix them for you even if they appear high severity years ago.
I haven't bothered for over 5 years. It's a waste of time, even if the issue high severity. You can google my name and Microsoft bug and see my rants at times in the past. Now I'm zen about it and just don't care. ;)
There's a reason why I'm no longer an FTE.
Here's a nice WCF bug that's active from 2013 - http://www.beta.microsoft.com/VisualStudio/feedbackdetail/view/779111/wcf-rest-service-two-set-cookie-http-headers-invalid-set-cookie-header-syntax
@windhandel
It's nice with VSCode as I believe this is a separate section of the team that gets to operate differently. Especially since this is open source you get to see a lot more of the ins & outs of how this team is operating. Given it's open source you get the opportunity to fix the code up yourself if you have the time and know how.
@windhandel It's a double edged sword. You might write bug-free code (do you?) but if nobody else is using it, it's not so great. On the other hand, if you are a mere mortal like the rest of us, and you write code that a lot of people use, you will be prompted to publish it with what you hope are not too many bugs as well as requests for new features. Life becomes a careful balance of fixing just enough bugs, adding just enough new features, to keep your code popular and useful. And, especially in the world of open source where anyone can fix bugs, we hope that everyone helps keep the balance.
BTW, did you know that WCF is open source? https://github.com/dotnet/wcf
Format my code, appear in the following format:
_self
.model
.personClassify(classify);
But I want to keep my code in the same line, for example:
How should I configure?
@kuaipaowoniu This is not that hard, but you'll want to learn more about regular expressions.
In VS Code, 1.17.0, search for this Regular Expression
([^\n]*)\n\.
and use this for the Replace part
$1.
Most helpful comment
Why is this closed? Multiline regex find and replace does not work in 1.13.1. Looks like it finds only in opened buffers, but how useful is that?