I came across some problem in my neovim settings, and something weird happens when I use vim.opt:remove to change the formatoptions.
First, my default formatoptions is jcroql, because I run :verbose set formatoptions? and it returns:
formatoptions=jcroql
Last set from /usr/share/nvim/runtime/ftplugin/lua.vim line 18
Then, I want to change it, removing ro options. According to this answer, I should use after-directories to change this option.
So, I create a file ~/.config/nvim/after/ftplugin/lua.lua to change this option for lua files. And here comes the question.
I wrote in this file:
vim.opt.formatoptions:remove('ro')
-- vim.cmd([[set fo-=ro]])
Using neovim lua api to change formatoptions, I found
formatoptions=ojqlcr
Last set from Lua
The order and modifier changes, but ro is still in formatoptions.
Using native way to change formatoptions, aka,
-- vim.opt.formatoptions:remove('ro')
vim.cmd([[set fo-=ro]])
I found:
formatoptions=jcql
Last set from Lua
And it works.
Why vim.opt.formatoptions:remove doesn't behave what is descriped in it's document? I expect vim.opt.formatoptions:remove('ro') is equal to set fo-=ro in vim script.
Additionally, is there a way to globally remove ro in all filetypes' formatoptions using after-directories?
Inspired by this answer, I tried to use separated
removecalls like this:And now this works! I found
:verbose set formatoptions?to be:Although the default
formatoptionsisjcroql, including aroin middle. I found that/usr/share/nvim/runtime/ftplugin/lua.vim line 18isMaybe it's just a coincidence to see
jcroqlin theformatoptions.