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) 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 ...
:lua print(vim.bo.filetype) shows the correct type - why is that?