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

[Bug]: buffer jumping using ordinal numbers #652

Open
1 task done
Martinits opened this issue Jan 2, 2023 · 2 comments
Open
1 task done

[Bug]: buffer jumping using ordinal numbers #652

Martinits opened this issue Jan 2, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Martinits
Copy link

Martinits commented Jan 2, 2023

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

I'd like to use ordinal numbers on buffer titles, but example mappings lua require("bufferline").go_to_buffer(1, true) in the doc seems not to work with jumping with ordinal numbers. It just does the same thing as BufferLineGoToBuffer 1.
For example, I opened file2 first, it gets an ordinal number 1. Then I opened file1, which gets 2 and show on the left of file2 since I configured them to be sorted by directory.
image
When I press leader1, it goes to file1.

What did you expect to happen?

It should go to file2 with number 1.

Config

require('bufferline').setup {
    options = {
        mode = "buffers",
        numbers = function(opts)
            local tmpid = opts.ordinal > 9 and 10 or opts.ordinal
            local icons = {"", "", "", "", "", "", "", "", "", ""}
            return icons[tmpid]
        end,
        -- unrelated configs omitted
        sort_by = 'directory'
    },
}

vim.keymap.set('n', '<LEADER>1', '<cmd>lua require("bufferline").go_to_buffer(1, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>2', '<cmd>lua require("bufferline").go_to_buffer(2, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>3', '<cmd>lua require("bufferline").go_to_buffer(3, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>4', '<cmd>lua require("bufferline").go_to_buffer(4, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>5', '<cmd>lua require("bufferline").go_to_buffer(5, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>6', '<cmd>lua require("bufferline").go_to_buffer(6, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>7', '<cmd>lua require("bufferline").go_to_buffer(7, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>8', '<cmd>lua require("bufferline").go_to_buffer(8, true)<cr>', {silent = true})
vim.keymap.set('n', '<LEADER>9', '<cmd>lua require("bufferline").go_to_buffer(9, true)<cr>', {silent = true})

Additional Information

...

commit

No response

@Martinits Martinits added the bug Something isn't working label Jan 2, 2023
@jemag
Copy link

jemag commented Sep 7, 2023

I have the same problem. It is apparent for me when pinning buffers.

For example, when pinning the third buffer, it will go in 2nd position:
image
In this situation,

vim.keymap.set({ "n", "x" }, "<leader>2", "<cmd>lua require('bufferline').go_to(2, true)<cr>", { desc = "Buf 2" })

will still go to the buffer with ordinal number 3

@jackielii
Copy link
Contributor

jackielii commented Dec 7, 2023

I think the go_to with absolution position is correct, I just wished the pinned buffer ordinal number changes too. Or better add a "absolute_number" in the numbers option

update: you can use this for absolute numbering:

          numbers = function(opts)
            local state = require("bufferline.state")
            for i, buf in ipairs(state.components) do
              if buf.id == opts.id then return i end
            end
            return opts.ordinal
          end,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants