Skip to content

Refactor repo to optimize structure and plugin loading #14

@BenGH28

Description

@BenGH28

Summary

The repo structure is already solid and typical for a Lua-based Neovim config, but a few targeted refactors will improve lazy-loading, maintainability, and clarity:

Key improvements to make:

1. Move plugin runtime code out of plugin/ and into lua/ modules (especially for which-key)

  • Files in plugin/ (like plugin/whichkey.lua) are sourced eagerly by Neovim at startup, even with lazy.nvim. This can break lazy-loading and increase startup time.
  • Solution: Create lua/core/whichkey.lua (or similar module for each plugin with runtime code), move all which-key registration there, and invoke it from the relevant plugin's config in lua/plugins/ui.lua.
  • Example:
    • Before: plugin/whichkey.lua runs at startup.
    • After: lua/core/whichkey.lua configured from lazy.nvim’s plugin table.

2. (Optional) Break up autocmds.lua and other core glue files by feature

  • As autocmds and core helpers grow, split them into smaller files under lua/core/autocmds/, and require a single setup module (lua/core/autocmds/init.lua).

3. Move all core helpers and glue (e.g., go_to_plugins.lua, mylazy.lua) under lua/core/ for clarity

4. Move long inline plugin configs (from plugin entries in lua/plugins/) into dedicated config files (lua/plugins/config/*.lua)

  • Keeps the plugin list focused and makes testing, linting, and maintenance easier.

5. Remove duplicate mappings and accidental globals

  • There are duplicate <leader>fvt mappings and some M = {} globals that should be local M = {}.
  • Use a linter and code search (e.g., rg '<leader>fvt', rg '^M = {}') to catch and fix them.

6. Document the intended layout and conventions briefly in README.md


Step-by-step checklist

  • Refactor plugin runtime (which-key) out of plugin/ and into a module, and update lazy.nvim config
  • (Optional) Split autocmds.lua into lua/core/autocmds/*
  • Move helpers (like go_to_plugins.lua and mylazy.lua) into lua/core/
  • Move long plugin configs to lua/plugins/config/*
  • Remove duplicates, accidental globals, and add log on failed requires
  • Add a short architecture section to README.md

See assistant comment in this issue for migration examples/samples.

Benefit:

  • Ensures true lazy-loading, speeds up startup, and future-proofs config growth for maintainability.

Assignee: @BenGH28

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions