Set global 'formatoptions' that doesn't get overwritten by runtime files #26885
-
In my init.lua (or really a file sourced by init.lua) I have: vim.opt.formatoptions = "cqrnj" -- default: "tcqj" But for most files I open (e.g. Lua files) {
c = true,
j = true,
l = true,
n = true,
o = true,
q = true,
r = true
} and
which makes sense since I can see neovim/runtime/ftplugin/lua.vim Line 20 in 444f37f But I would like my formatoptions to be global and not overwritten by the runtime files. What is the recommended way to do this? So far I have been making sure my settings work as expected by using the following autocmd: local daniel_format = vim.api.nvim_create_augroup('DanielFormat', { clear = true })
vim.api.nvim_create_autocmd("BufEnter", {
group = daniel_format,
pattern = "*",
callback = function()
vim.opt.formatoptions = "cqrnj"
end
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
These will change local |
Beta Was this translation helpful? Give feedback.
There might be more targeted events (
FileType
,OptionSet
), but an autocommand -- or localftplugin
is The Way.