2

Is there any way to tell vim to use the NUL character as the end-of-line marker instead of LF, CR/LF, or CR?

More generally, is it possible to use any arbitrary character or sequence of characters as the EOL marker?

NOTE: I do not want to convert line endings. I know how to do that, I've been doing it for years. I have some pseudo-XML files that use NUL as the "line" separator and want to edit them as they are, without vim treating the file as one huge long line (which is difficult to read and painfully slow to navigate and edit) and without mangling the files by accidentally converting some or all NULs to LFs.

2

If you look at the buf_write() function in fileio.c ("abandon all hope ye who enter here", we see (slightly simplified):

if (fileformat == EOL_UNIX)
    *s++ = NL;
else
{
    *s++ = CAR;                 /* EOL_MAC or EOL_DOS: write CR */
    if (fileformat == EOL_DOS)  /* write CR-NL */
        *s++ = NL;
}

Full source here.

While you could easily add a NULL byte to the end of lines with a BufWritePre autocommand, I see no functionality to not write a NL or CRNL here, so you'd end up with NULL + NL.

  • Thanks for the nicely researched answer, but NUL+LF is no good for these files. The program that uses them would choke on unexpected LFs. It would be better to just convert NUL to LF with sed or tr or something, edit the files, and then convert back again. I was hoping there was a way to do it entirely in vim, without having to hack the source for every upgrade or keep a special local version for the rare occasions I need to do something like this. – cas Apr 4 '17 at 17:52
  • @cas Unfortunately what you want isn't possible with Vim at the moment; not without post-processing with external tools, anyway (you could use tr '\n' '\x00' or something to that effect). – Martin Tournoij Apr 4 '17 at 18:11

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.