How can i tidy up my init.lua
, I have packer , globals , keymaps , plugin configs and the kitchen sink in a single file… Its coming up to 2 years of configs and almost 1K lines ,and dont want it to get unmanageable.
I do have programming knowledge but not in lua.
I tried looking at several configs and a git repo (nanotee/nvim-lua-guide) but without much luck .
Maybe just split all those core subjects (plugins, keymappings, plugin configs) into separate files and keep the init.lua
file just for sourcing those directories/files? The directory structure should look something like this:
📂 ~/.config/nvim
├── 🌑 init.lua
├── 📂 lua
│ ├── 🌑 plugins.lua
│ ├── 🌑 keybindings.lua
│ ├── 🌑 globals.lua
│ └── 📂 configs
│ ├── 🌑 signs.lua
│ └── 🌑 file-explorer.lua
Make sure to require (source) these files in your init.lua
. This is where your knowledge from nvim-lua-guide comes in handy: https://github.com/nanotee/nvim-lua-guide#modules
If you don’t mind watching a video, I did a YT on doing that recently: Better Neovim plugin setup! Use Packer, break your init.lua into modules, look like a hero! - YouTube
Similar approach to what @dchuri suggests.
I followed Christian Chiarulli’s GitHub - LunarVim/Neovim-from-scratch: A Neovim config designed from scratch to be understandable and I’m happy with it.
But when I tried to follow TJ DeVries’s Bash2Basics: Neovim Lua Plugin From Scratch, I need to put my files in $HOME/.local/share/nvim/site/pack/packer/start
And DevOnDuty’s Create Neovim Plugins with Lua does everything in a sub-directory of $HOME.
Different people have different ways of doing things, just need to adjust a little bit to get it work.
make a folder, call it “lua”. Shove anything you want in there and all *.lua files there will be available for “require” in your init.lua.
Example:
Assuming PWD is “$HOME/.config/nvim”.
If you just wanna source some “./lua/keymap.lua”, in your init.lua write “require(‘keymap’)” and it’s done. Beware: The example above is NOT for Lua modules.