Home > Mobile >  Search for carriage return character '\r' in VS Code
Search for carriage return character '\r' in VS Code

Time:10-03

In visual studio I am able to search for carriage return character by searching for the regex \r like this:



If I do the same thing on VS Code it finds nothing:




Why is it that on VSCode that does not work? How can I search for a carriage return character on VS Code? Or how can I search for files that have the CRLF line endings? Note how on the last picture on the bottom VS-Code recognizes it has CRLF endings. How can I search for files that have those line endings?

CodePudding user response:

See Regex Engine can't recognize carriage return in find menu .

Find (in editor, also used for open editors during Find in Files) uses JS engine and normalized text for editor (without \r).

So easier workaround to use \r?\n as "universal" approach or close open editors if \r is crucial.

So use \r?\n.

Also related see Can't find the \r caracter with the new VS Code 1.9 Update :

VSCode prohibits by design to create inconsistent End-Of-Line sequences. That means it will never allow an edit to do anything inside the End-Of-Line sequence. The End-Of-Line sequence can be changed from the status bar in the bottom right (where LF or CRLF sits)

So, if an extension, if the find widget, etc. tries to edit or "target" in any way in between a \r and a \n in a file with \r\n End-Of-Line sequences the edit will be adjusted and moved either to before the \r\n or after the \r\n.

As a result, in a CRLF file, there is no \r without a \n immediately after it. Nothing has been lost, there is no need to distinguish the \r from the \r\n since nothing can be done to that character by itself.

  • Related