As mentioned by @cassava, your problem may be due to this PR, which changes formatexpr
to take its initial value from the LSP (as I understand it).
There are a few suggestions for workarounds in this issue, linked to from this Reddit thread, of which using gw
instead of gq
seems like the easiest one-off workaround, and this snippet works for me for a more robust approach:
-- Use internal formatting for bindings like gq.
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
vim.bo[args.buf].formatexpr = nil
end,
})
Alternatively, I am using the below to restore the prior behavior specifically for Python / pylsp:
local pylsp_on_attach = function(client, bufnr)
default_lsp_on_attach(client, bufnr)
-- Restore gqq
vim.api.nvim_buf_set_option(bufnr, "formatexpr", "")
end
nvim_lsp.pylsp.setup({
-- ...
on_attach = pylsp_on_attach,
-- ...
})
formatexpr
is set tov:lua.vim.lsp.formatexpr()
. This makes Neovim use a language server to format, also withgq
. I don't how how to preserve that and also be able to wrap text withgq
. You can:set formatexpr=
to just get the wrapping.:set formatexpr=
madegq
work again. Although I'm curious, what else might I be losing by un-settingformatexpr
?:set formatexpr=
.