Skip to content
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

navigation only for open buffers? #38

Open
daUnknownCoder opened this issue Jul 2, 2024 · 0 comments
Open

navigation only for open buffers? #38

daUnknownCoder opened this issue Jul 2, 2024 · 0 comments

Comments

@daUnknownCoder
Copy link

daUnknownCoder commented Jul 2, 2024

hi, i was trying to setup the <leader>%s keys in 1-10 like this:

  {
    "j-morano/buffer_manager.nvim",
    lazy = true,
    event = { "BufAdd", "BufDelete", "BufEnter" },
    keys = {
      { ",,", "<cmd>lua require('buffer_manager.ui').toggle_quick_menu()<CR>", desc = "Buffer Manager" },
    },
    config = function()
      local bm_status_ok, bm = pcall(require, "buffer_manager")
      if not bm_status_ok then
        print("Buffer Manager not found!")
      end
      bm.setup({
        select_menu_item_commands = {
          edit = { key = "<CR>", command = "edit" },
          v = { key = "<C-v>", command = "vsplit" },
          h = { key = "<C-h>", command = "split" },
        },
        short_file_names = true,
        short_term_names = true,
      })
      local keys = "1234567890"
      local bmui = require("buffer_manager.ui")
      for i = 1, #keys do
        local key = keys:sub(i, i)
        local desc = "Switch Buffer: " .. (i == 10 and "10" or key)
        vim.keymap.set({ "t", "n" }, string.format(",%s", key), function()
          bmui.nav_file(i)
        end, { desc = desc, noremap = true })
      end
      vim.keymap.set({ "t", "n" }, ",s", function()
        bmui.toggle_quick_menu()
        vim.defer_fn(function()
          vim.fn.feedkeys("/")
        end, 50)
      end, { desc = "Search Buffer", noremap = true })
      vim.api.nvim_set_hl(0, "BufferManagerModified", { fg = "#50fa7b" })
    end,
  },

but it registers 10 keys even though i only have 3 buffers which is not feasible, so i got chatgpt to work and it got me something like this:

local function count_buffers()
  local count = 1
  for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
    if vim.api.nvim_buf_is_loaded(buffer) then
      count = count + 1
    end
  end
  return count
end

local buffer_count = count_buffers()

for i = 1, buffer_count do
  local key = keys:sub(i, i)
  vim.keymap.set({ "t", "n" }, string.format(",%s", key), function()
    bmui.nav_file(i)
  end, { desc = "Switch Buffer: " .. key, noremap = true })
end

so it does work but i use which-key.nvim which doesnt update so can i get something to update that?

chatgpt didnt work this time sadly 😢

@daUnknownCoder daUnknownCoder changed the title there is no setup function (lazy) navigation only for open buffers? Jul 2, 2024
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

No branches or pull requests

1 participant