Why wrap neovim config in a table?

I’ve noticed that some neovim configs are separated into several files or folders and the content of each file is wrapped in code like so:

local M = {}

function M.name()
   bunch of code

return M

I never do this and I’m curious if there’s any advantage to this approach?

I’m new to Lua so I might be wrong, but I think it’s to namespace the functions so that they don’t clash with anything else.

M stands for module. I believe this is just a convention.

Hope that helps.

1 Like