Nvim config folder structure

Till now I have been trying to configure my neovim using one huge init.lua file. This is what I guess with my limited knowledge of vim and was trying to do to in neovim as well.

But recently I came across some old youtube videos by Leeren which went describe the various folder structure like “after”,“ftdetect” etc which one can use to configure vim.
Wanted to know if there is any optimum protocol for doing this folder and file structure for doing this. Does it improve the performance of NEOVIM if we do this instead of one init.lua file.
I am new to this and trying learn the best practice

I’m interested in this too.
Here is my structure, it works and makes sense to me but I’m a complete noob in lua
 .
├──  init.lua
├──  lua
│ ├──  compe-settings.lua
│ ├──  formatter-settings.lua
│ ├──  keymappings.lua
│ ├──  language-servers
│ │ ├──  css.lua
│ │ ├──  html.lua
│ │ ├──  init.lua
│ │ ├──  json.lua
│ │ ├──  luals.lua
│ │ ├──  python.lua
│ │ ├──  typescript.lua
│ │ └──  vue.lua
│ ├──  load-plugins.lua
│ ├──  luaLine-settings.lua
│ ├──  options.lua
│ ├──  telescope-settings.lua
│ └──  treesitter-settings.lua
├──  README.md

put all your lua file in a unique name folder
/ lua/ xyzavc/…
it avoid conflict with a plugin use a same name.

you can put it on plugins/*.lua
if that code doesn’t need to reuse using require

I suggest reading the help for ‘runtimepath’. (Neo)vim looks for configuration files in specific directories, which determine the order in which those files are loaded. You can place both .vim and .lua files in those directories, and .vim files will be loaded before .lua files.

For example, suppose you want to set some options for a plugin called foo; if you place your configuration in ~/.config/nvim/after/plugin/foo.lua or in ~/.config/nvim/after/plugin/foo/bar.lua, neovim will load it automatically after foo has been loaded (and it won’t load that configuration if plugins have not been loaded).

On the other hand, most options specific to a given file type, say tex, go in ~/.nvim/ftplugin/tex.lua.

3 Likes