Skip to content

Conversation

@john-mutuma
Copy link
Owner

What does this PR do?

This PR refactors and modularizes the way keymaps and highlight overrides are managed for several plugins in the NairoVIM configuration. It introduces a more maintainable and scalable approach by moving plugin-specific keymaps and highlight definitions into dedicated modules, and provides utility functions for applying them consistently.

Changes made in this PR:

  • Keymaps Modularization:

    • Extracted keymap definitions for plugins (gitsigns, lazygit, copilot-chat, glance, lspsaga, nvim-ide, nvim-tree, telescope) into separate files under plugins/customizations/keymaps/.
    • Updated plugin configs to use a new common_utils.map utility for applying keymaps, supporting both global and buffer-local mappings.
    • Added a new type definition for nairovim.KeymapDef in types/keymap.lua.
  • Highlights Modularization:

    • Moved highlight group definitions for plugins (glance, lazygit, nvim-tree) into separate files under plugins/customizations/highlights/.
    • Added a new type definition for nairovim.highlightspec in types/highlight.lua.
    • Introduced common_utils.apply_highlights utility to apply and reapply highlight groups on colorscheme changes.
  • Plugin Config Refactors:

    • Updated plugin configs (gitsigns, lazygit, glance, lspsaga, nvim-ide, nvim-tree, telescope) to use the new modular keymap and highlight approach.
    • Removed inline keymap and highlight logic from plugin configs for improved clarity.
  • General Improvements:

    • Updated the main keymaps file to use a table-driven approach and the new mapping utility.
    • Improved maintainability and discoverability of customizations.

Why is it needed?

  • Reduces duplication and centralizes plugin-specific customizations.
  • Makes it easier to add, update, or remove keymaps and highlights for individual plugins.
  • Ensures highlight overrides persist across colorscheme changes.
  • Improves code readability, maintainability, and scalability for future enhancements.

How have the changes been tested?

  • Manual testing: Verified that all keymaps and highlight overrides work as expected for each plugin after the refactor.
  • Checked that highlights persist after changing colorschemes.
  • Confirmed that buffer-local and global keymaps are correctly applied.

Screenshots (if applicable)

N/A (no UI changes, only configuration refactor)

Checklist

  • All plugin keymaps are modularized and applied via utility
  • All highlight overrides are modularized and colorscheme-aware
  • Type definitions for keymaps and highlights are added
  • Plugin configs are updated to use the new approach
  • Manual testing performed for all affected plugins

Previously, when no changes were detected in the git diff, the string
"No changes detected" was returned. This commit updates the logic to
return an empty string ("") instead. This change provides cleaner and
more predictable output for downstream consumers of the git diff content
in the Copilot Chat plugin.

Affected file:
- v2/nvim/lua/nairovim/plugins/lsp/copilot-chat.lua
- Extracted all gitsigns keymaps into
  `plugins/customizations/keymaps/gitsigns.lua` for better modularity.
- Introduced a `KeymapDef` type in `types/keymap.lua` to standardize
  keymap definitions.
- Added a utility function `map` in `utils/common.lua` to map a list of
  keymaps using `vim.keymap.set`, supporting buffer-local mappings.
- Updated `plugins/gitsigns.lua` to use the new keymap module and
  utility, simplifying the on_attach logic.

This refactor improves maintainability and consistency of keymap
definitions across the configuration.
Refactored the Copilot Chat key mapping to use the standardized
KeymapDef structure. This improves consistency and maintainability
across keymap definitions, making future updates and integrations
easier to manage.
Refactored highlight group definitions in the Glance LSP plugin to use
the `vim.api.nvim_set_hl` API directly with a Lua table, replacing the
manual command string construction. This improves readability and
maintainability. Added a new `highlightspec` type definition in
`types/highlight.lua` to document the expected highlight table format.

Changes:
- Updated highlight group definitions to use Lua table keys (`italic`,
  `bold`, `fg`, `bg`) instead of legacy `gui`, `guifg`, `guibg`.
- Used `vim.api.nvim_set_hl` for all highlight groups in a loop.
- Added `highlightspec` type definition for better type hinting and
  documentation.
- Removed redundant manual highlight linking at the end of the function.
- Change all keymap type annotations from `KeymapDef` to
  `nairovim.KeymapDef` for improved clarity and namespacing.
- Move LazyGit keymap definition to its own file
  (`customizations/keymaps/lazygit.lua`) and remove direct keymap in
  plugin config.
- Update LazyGit plugin config to use the new keymap definition and the
  `common_utils.map` function for consistency.
- Update utility and type annotations to use the new namespaced type.
- Moved nvim-ide keymap definitions to a dedicated module at
  plugins/customizations/keymaps/nvim-ide.lua for better organization.
- Updated nvim-ide plugin config to load keymaps from the new module and
  apply them using the common_utils.map function.
- Removed inline keymap definitions and helper from nvim-ide plugin
  config.
- Improved documentation for the map utility function in
  utils/common.lua.
- Moved <C-n> toggle keymap for NvimTree to a new keymap module
  (customizations/keymaps/nvim-tree.lua) using nairovim.KeymapDef.
- Updated nvim-tree plugin config to load keymaps via common_utils.map.
- Refactored NvimTree highlight overrides to use vim.api.nvim_set_hl
  and added an autocmd for ColorScheme changes.
- Updated keymap type definition to use vim.keymap.set.Opts for
  improved type safety.
- Minor cleanup in glance.lua autocmd group creation.
- Extracted Telescope-related keymaps from the main plugin config
  (`plugins/telescope.lua`) into a dedicated keymaps module
  (`customizations/keymaps/telescope.lua`).
- Replaced inline keymap definitions with a table-based approach using
  `nairovim.KeymapDef[]` and a common utility for mapping.
- Updated the Telescope plugin config to require and apply the new
  keymaps module.
- This improves maintainability and centralizes keymap management for
  Telescope.
- Renamed the `highlightspec` type to `nairovim.highlightspec` for
  better namespacing and clarity.
- Updated type annotations in `glance.lua` and `nvim-tree.lua` to use
  the new `nairovim.highlightspec` type.
- Adjusted the type definition in `types/highlight.lua` accordingly.
- This change improves type clarity and avoids potential naming
  conflicts.
- Refactored LSP-related keymaps out of core/keymaps.lua into dedicated
  modules under plugins/customizations/keymaps/ for Glance and Lspsaga.
- Added glance.lua and lspsaga.lua keymap definition files, each
  exporting a nairovim.KeymapDef[] table for their respective plugin.
- Updated Glance and Lspsaga plugin configs to set up their keymaps on
  LspAttach using the new modules and the common_utils.map utility.
- core/keymaps.lua now only contains general/global keymaps and applies
  them via common_utils.map.
- This modular approach improves maintainability and plugin-specific
  customization of keymaps.
- Moved Glance highlight group definitions to a new module:
  `plugins/customizations/highlights/glance.lua`.
- Added a generic `apply_highlights` utility to
  `utils/common.lua` for applying and auto-updating highlight groups
  on colorscheme changes.
- Updated Glance LSP plugin config to use the new highlight utility
  and highlight definitions module.
- Simplified highlight override logic and improved maintainability.
- Moved highlight group definitions for LazyGit and NvimTree into
  separate files under customizations/highlights for better modularity
  and reuse.
- Updated lazygit and nvim-tree plugin configs to use the new highlight
  modules and the common_utils.apply_highlights function for consistent
  highlight application and autocmd management.
- Fixed typo in lspsaga LspAttach autocmd augroup name.
- Improved apply_highlights utility to correctly reapply highlights on
  colorscheme changes by passing the getter function instead of the
  result.

This refactor improves maintainability and consistency of highlight
customizations across plugins.
Copy link
Owner Author

@john-mutuma john-mutuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@john-mutuma john-mutuma merged commit 2befb9d into develop May 27, 2025
@john-mutuma john-mutuma deleted the user/johnmutuma/continous-improvements branch May 27, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants