Help: Remap Ctrl-n to "switch to n-th buffer" #3746
-
I have this code in my keymaps.lua
The function is called when Ctrl-n is pressed, but the buffer numbers are not sequential. Executing How can I remap my keys so that I can easily jump to a specific buffer using Ctrl-n ? |
Beta Was this translation helpful? Give feedback.
Answered by
dpetka2001
Jun 20, 2024
Replies: 1 comment 8 replies
-
Something like the following could work local buffers = {}
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_valid(buf) and vim.bo[buf].buftype == "" then
table.insert(buffers, buf)
end
end
for k, v in ipairs(buffers) do
vim.keymap.set("n", "<M-" .. k .. ">", "<cmd>buffer " .. v .. "<cr>", { desc = "go to buffer" })
end But I personally prefer setting a keymap with Bufferline (if you use it) to do the same vim.keymap.set("n", "<leader>bb", function()
require("bufferline").pick()
end, { desc = "Pick buffer" }) |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I put the following in
~/.config/nvim/lua/config/autocmds.lua
and it seems to do what you wantTest it out.