nvim set filetype picker
whenever i open a new buffer and paste stuff into it, formatting is lost. this happens because neovim doesn’t know what type of file it’s dealing with. setting the correct filetype manually each time is tedious. that’s where a filetype picker comes in handy.
changing filetypes in neovim can be faster. this post introduces a lua-based telescope picker for setting filetypes in neovim.
the problem
switching between different file types in neovim requires typing commands like :set filetype=python
. this takes time, especially when working with multiple file types.
the solution
we’ve made a telescope-based filetype picker that lets you select from a list of common filetypes. here’s the core code:
how to use
- save the code in your neovim config (e.g.,
~/.config/nvim/lua/my_utils/filetype_picker.lua
) - add this to your
init.lua
:
- press
<leader>ft
in normal mode to open the picker - select your filetype
customization
to add or remove filetypes, edit the filetypes
table in the code. this lets you adapt it to your needs and commonly used languages.
conclusion
this telescope-based filetype picker makes changing filetypes in neovim faster. it reduces the time spent on editor commands, letting you focus more on coding. try it and see if it helps your neovim workflow.