Skip to content

refactor: use loop to generate buffer navigation keymaps#1

Open
sazary wants to merge 1 commit intomasterfrom
open-inspect/9e444786b37a960b5c7df11812d2a179
Open

refactor: use loop to generate buffer navigation keymaps#1
sazary wants to merge 1 commit intomasterfrom
open-inspect/9e444786b37a960b5c7df11812d2a179

Conversation

@sazary
Copy link
Owner

@sazary sazary commented Feb 1, 2026

Summary

Refactored repetitive buffer navigation keymap definitions into a clean loop, reducing code duplication from 9 individual keymap.set calls to a single loop.

Changes

  • Replaced 9 repetitive keymap definitions with a for loop that generates keymaps 1-9
  • Maintains identical functionality without any behavior changes
  • Improves maintainability and makes the code more DRY

Why

  • Reduces code repetition in keymaps configuration
  • Makes it easier to maintain and extend buffer navigation keymaps in the future
  • No functional changes, purely a code quality improvement

Created with Open-Inspect

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.
Copilot AI review requested due to automatic review settings February 1, 2026 15:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.set calls with a for i = 1, 9 do ... end loop.
  • Builds the lhs/rhs/desc strings dynamically based on i.

💡 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" })
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

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" })

Copilot uses AI. Check for mistakes.
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.

1 participant

Comments