I am using neovim (0.6) and its built-in LSP with clangd-12 for C++. When reformatting a file that uses DOS-style line endings, it for some reason uses a double carriage return, resulting in one ^M to show up in the editor.

To illustrate: I have the following file (output with cat -A to show the line endings):

int main(int argc, char *argv[])^M$
    int foo = 42; return 0;^M$

After reformatting with vim.lsp.buf.formatting(), it looks like this:

int main(int argc, char *argv[])^M$
    int foo = 42;^M^M$
    return 0;^M$

Note the ^M^M in the line break caused by the formatting.

This does not happen, when I run clang-format-12 on the file, so it seems to be related to the nvim/lsp setup rather than to the clang-format configuration.

Any idea what could be the problem here?

In case it's relevant, I'm on Ubuntu 20.04.

  • 1
    Probably the LSP somehow doesn't know (or didn't take into account?) the DOS-endings. Odd that it should only happen on one line… at any rate, I suspect your best bet at solving this lies with the LSP-client maintainers.
    – D. Ben Knoble
    Jan 11 at 16:47
  • It only happens on the line breaks that are added by the reformatting, existing ones are not changed.
    – luator
    Jan 12 at 15:26

Your Answer

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

Browse other questions tagged or ask your own question.