-
Notifications
You must be signed in to change notification settings - Fork 1
2025-05-27: Modularize Keymaps & Highlights for Plugin Customization #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
john-mutuma
commented
May 27, 2025
Owner
Author
john-mutuma
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
plugins/customizations/keymaps/.common_utils.maputility for applying keymaps, supporting both global and buffer-local mappings.nairovim.KeymapDefintypes/keymap.lua.Highlights Modularization:
plugins/customizations/highlights/.nairovim.highlightspecintypes/highlight.lua.common_utils.apply_highlightsutility to apply and reapply highlight groups on colorscheme changes.Plugin Config Refactors:
General Improvements:
Why is it needed?
How have the changes been tested?
Screenshots (if applicable)
N/A (no UI changes, only configuration refactor)
Checklist