refactor: use loop to generate buffer navigation keymaps#1
Open
refactor: use loop to generate buffer navigation keymaps#1
Conversation
Reduces repetitive code by generating buffer navigation keymaps 1-9 in a loop instead of 9 individual keymap.set calls. Improves maintainability without changing functionality.
There was a problem hiding this comment.
Pull request overview
Refactors Neovim buffer navigation keymaps to reduce repetition by generating <leader>1–<leader>9 mappings in a loop.
Changes:
- Replaced nine explicit
vim.keymap.setcalls with afor i = 1, 9 do ... endloop. - Builds the lhs/rhs/
descstrings dynamically based oni.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+11
to
+12
| for i = 1, 9 do | ||
| vim.keymap.set("n", "<leader>" .. i, "<cmd>BufferLineGoToBuffer " .. i .. "<cr>", { desc = "Go to the " .. i .. "th buffer" }) |
There was a problem hiding this comment.
The generated desc uses .. i .. "th", which results in grammatically incorrect labels like "1th/2th/3th buffer". This also changes the user-visible keymap descriptions compared to the previous "1st/2nd/3rd" wording.
Consider generating the correct ordinal suffix (e.g., 1st, 2nd, 3rd, otherwise th) or using an explicit description table for 1–9 so the descriptions remain correct.
Suggested change
| for i = 1, 9 do | |
| vim.keymap.set("n", "<leader>" .. i, "<cmd>BufferLineGoToBuffer " .. i .. "<cr>", { desc = "Go to the " .. i .. "th buffer" }) | |
| local buffer_ordinals = { "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th" } | |
| for i = 1, 9 do | |
| vim.keymap.set("n", "<leader>" .. i, "<cmd>BufferLineGoToBuffer " .. i .. "<cr>", { desc = "Go to the " .. buffer_ordinals[i] .. " buffer" }) |
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
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.
Summary
Refactored repetitive buffer navigation keymap definitions into a clean loop, reducing code duplication from 9 individual
keymap.setcalls to a single loop.Changes
forloop that generates keymaps 1-9Why
Created with Open-Inspect