I noted today that formatting lines with gq (with formatoptions set to qtjcrl and unset formatexpr) no longer works when I have the LSP enabled. As soon as I run :LspStop and use gq it works as expected.
How can I properly configure Neovim and the LSP so it preserves the internal formatting behavior when using gq?
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Disable lsp formatexpr (use the internal one)
vim.opt.formatexpr = ""
on_attach = on_attach,
It’s working for me. The only drawback I found with this is that this is applied to every LSP that uses this on_attach function, and maybe one would want to actually use the formatter that the LSP provides. A solution would be to write a different on_attach function for those.