1

How to get the current file type in lua with neovim? I tried following but all of them returns nil.

print(vim.g.filetype)
print(vim.b.filetype)
print(vim.w.filetype)
print(vim.t.filetype)
print(vim.v.filetype)
1

filetype is a buffer-local option, so you can access it with:

vim.bo.filetype

From :h lua-vim-options:

From Lua you can work with editor |options| by reading and setting items in
these Lua tables:

vim.w
   ...

vim.bo                                                  *vim.bo*
       Get or set buffer-scoped |local-options|. Invalid key is an error.
       Example:
           vim.bo.buflisted = true
           print(vim.bo.comments)

vim.wo
   ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.