0

I can replace some text with \n if i enable the regex by clicking the regex icon next to the find input box.

But when i try to find a newline, i can't get it to work. I tryed to find \n and [\n]. But none worked. The only solution which worked was [\s] but it's not ideal. But for now it better then nothing i guess.

Is it possible to find a newline in VSCode?

Jo Smo
  • 6,923
  • 9
  • 47
  • 67
  • The link you gave @Fraser only explains how to replace it with a newline... But not how to find a newline. I red that already. – Jo Smo Oct 24 '16 at 08:44
  • I don't get it. Why do sonme of you want to close my question? :O It was not answered and the link which you provided is NOT a duplicate. – Jo Smo Oct 24 '16 at 11:21
  • VSCode 1.17.2 on OSX can find EOL characters using, as the accepted answer in the suggested duplicate says, `$` in regex mode. Note that if "whole word" is also turned on, searching for `$` will find only blank lines. **_However_**, it will not _replace_ that EOL with anything, rather the characters in the "replace" field are prepended to the EOL. In order to find and replace EOLs, search for `\n` or `\r\n`, depending on the platform (or `\r`, if you have files from Mac OS 9 :-) ), with regex mode **on** and whole word **off** (https://stackoverflow.com/a/38257260/1112244). – Peter Nov 07 '17 at 01:59

1 Answers1

0

It would depend on the new line settings of your system, but in general on windows a new line is made from two characters, a carriage return \r followed by linefeed \n.

So the regex for a new line is \r\n

Fraser
  • 15,275
  • 8
  • 53
  • 104
  • I know. I'm on MacOS. And it's `\n`. You are right, on Windows it's `\r\n`. – Jo Smo Oct 24 '16 at 08:46
  • Do you think including pertinent information in the question would be helpful? – Fraser Oct 24 '16 at 10:39
  • I did? I never used \r\n in my question. Always \n. – Jo Smo Oct 24 '16 at 11:20
  • But it wasn't working so I presumed you must be doing something wrong for your system... – Fraser Oct 24 '16 at 11:21
  • Nope, it has to be something else... – Jo Smo Oct 24 '16 at 11:55
  • 1
    No, you didn't include pertinent information; this is the only time you mentioned Mac OS. I can find newline perfectly fine, I just find `\n` and set regex mode on. I'm on Linux. Clearly VSCode can do this, just not on your system right now... – Ian Emnace Oct 25 '16 at 07:27