Skip to content

Commit da231d7

Browse files
committed
Make buffer list dynamic
1 parent b260bc7 commit da231d7

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

config/nvim/lua/config/keymaps.lua

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ nmap("<C-Space>", "<CMD>NvimTmuxNavigateNext<CR>")
8989
nmap("<M-Right>", "<CMD>BufferLineCycleNext<CR>")
9090
nmap("<M-Left>", "<CMD>BufferLineCyclePrev<CR>")
9191

92-
nmap("<M-3>", "<leader>Tf")
93-
nmap("<M-2>", "<leader>Th")
94-
nmap("<M-1>", "<leader>Tv")
95-
9692
-- which-key setup
9793
-- unmap things that I want to use
9894
wunmap("`")
@@ -122,21 +118,30 @@ mappings["h"] = { "<CMD>nohlsearch<CR>", "No Highlight" }
122118

123119
-- buffers operations
124120
mappings["<Tab>"] = { "<CMD>edit #<CR>", "Previous Active Buffer" }
121+
122+
-- buffer quick switch index starts at 1 instead of 0
123+
wk.add({
124+
{
125+
"<leader>",
126+
group = "buffers",
127+
expand = function()
128+
local buf_entries = require("which-key.extras").expand.buf()
129+
buf_entries = vim.list_slice(buf_entries, 1, 9)
130+
-- Increment displayed index by 1 for each entry
131+
for _, entry in ipairs(buf_entries) do
132+
entry[1] = tostring(tonumber(entry[1]) + 1) -- Convert "0" → "1", etc.
133+
end
134+
135+
return buf_entries
136+
end,
137+
},
138+
})
125139
mappings["0"] = {
126140
function()
127141
require("neo-tree.command").execute({ toggle = false, dir = vim.uv.cwd() })
128142
end,
129143
"Focus Explorer",
130144
}
131-
mappings["1"] = { "<CMD>BufferLineGoToBuffer 1<CR>", "Select Buffer 1" }
132-
mappings["2"] = { "<CMD>BufferLineGoToBuffer 2<CR>", "Select Buffer 2" }
133-
mappings["3"] = { "<CMD>BufferLineGoToBuffer 3<CR>", "Select Buffer 3" }
134-
mappings["4"] = { "<CMD>BufferLineGoToBuffer 4<CR>", "Select Buffer 4" }
135-
mappings["5"] = { "<CMD>BufferLineGoToBuffer 5<CR>", "Select Buffer 5" }
136-
mappings["6"] = { "<CMD>BufferLineGoToBuffer 6<CR>", "Select Buffer 6" }
137-
mappings["7"] = { "<CMD>BufferLineGoToBuffer 7<CR>", "Select Buffer 7" }
138-
mappings["8"] = { "<CMD>BufferLineGoToBuffer 8<CR>", "Select Buffer 8" }
139-
mappings["9"] = { "<CMD>BufferLineGoToBuffer 9<CR>", "Select Buffer 9" }
140145

141146
mappings["b/"] = { "<CMD>Telescope buffers previewer=true<CR>", "Find" }
142147
mappings["b]"] = { "<CMD>BufferLineCycleNext<CR>", "Next" }

0 commit comments

Comments
 (0)