In the Vim documentation, it says that \r "matches < CR >", however for the result of replacement I could not find in the documentation a description of what it does. For example, imagine this:


On a unix system I know that this will replace newlines (0x0A) with newlines (0x0A) because on unix systems pressing < CR > produces a 0x0A.

However, what does it do on a Windows system? Will it replace 0x0A with 0x0A 0x0D (the Windows end of line)?


No, that is not true. Internally, \n will always match the line termination of a buffer regardless of whether the actual file uses <CR> or <NL> or <CR><NL> as line terminator (e.g. the 'fileformat') option does not matter.

In a replace command however, the \r in the replace part will always produce an actual new line, since the \n will insert a ASCII-NUL 0x0 into the buffer.

This is one of the implementation details, that can be seen on certain operations. Some of it is explained at :h CR-used-for-NL and :h NL-used-for-NUL

How the newline will finally being converted on writing the buffer, is determined by the 'fileformat' option.

  • This does not answer the question. Feb 21 '18 at 21:29
  • 4
    It does. \r will create a newline when used in the replace part of a :s command. However that has nothing to do with how the buffer line termination will be written and depends entirely on the 'fileformat' option. That is exactly what I have written above. What question is still open? Feb 21 '18 at 21:38
  • @ChristianBrabandt Just FYI, it almost doesn't matter whether you convince 'em or not since OP has stated that they will not accept an answer unless the person who answered upvotes the question. (Of the last 30 questions OP has asked just one has been accepted.)
    – B Layer
    Oct 13 '18 at 22:22
  • @BLayer yeah, I noticed. I am going to ignore the OP entirely and won't consider answering any questions from him anymore. Oct 14 '18 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.