0

If my init.lua contains the following:

vim.cmd('syntax enable')
print("test")
print(vim.bo.filetype)
print("test")

Then the output is:

test
test

But if I put some other configuration in between that takes time:

vim.cmd('syntax enable')
-- do stuff
print("test")
print(vim.bo.filetype)
print("test")

Then I get the correct filetype:

test
lua
test

My question is:

What do I need to do to make enabling filetype synchronous?

I checked :h vim.cmd and I searched the internet but I didn't find anything that explains or clarifies this.

3
  • It would be helpful to know better what you want to achieve. The vim.bo.filetype is about the filetype of the current buffer. At init.lua probably the only buffer loaded is init.lua itself. Later in autocmd FileType or in the ftplugin/filetype.lua handler the vim.bo.filetype variable should be set. Commented Jun 6 at 19:42
  • "At init.lua probably the only buffer loaded is"—this depends entirely on how Vim or Neovim process arguments that load buffers, but if you're editing init.lua it's not loaded in a buffer. See :help startup. I agree with @VivianDeSmedt though that init.lua is not the right place to try checking filetypes.
    – D. Ben Knoble
    Commented Jun 7 at 15:54
  • In other words, it would help to clarify your actual goal (this might be an XY problem) so that we can help you solve that.
    – D. Ben Knoble
    Commented Jun 7 at 15:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.