bufferline.nvim icon indicating copy to clipboard operation
bufferline.nvim copied to clipboard

[Feature]: Make `BufferLineMovePrev/Next` work with tabs

Open andresatierf opened this issue 2 years ago • 9 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

What happened?

The issue is that when using BufferLineMove[Prev/Next] command in a tab, other tabs are also affected

What did you expect to happen?

Only the buffers in the current tab change position

Config

{
  close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions"
  right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions"
  offsets = { { filetype = "NvimTree", text = "", padding = 1 } },
  separator_style = "thin", -- "slant" | "thick" | "thin" | { 'any', 'any' },
  show_tab_indicators = true,
  hover = {
    enabled = false,
    delay = 200,
    reveal = { "close" },
  },
  diagnostics = "nvim_lsp",
  diagnostics_indicator = function(count, level, diagnostics_dict, context)
    local icons = {
      hint = " ",
      info = " ",
      warning = " ",
      error = " ",
    }
    local icon = icons[level]
    return " " .. icon .. count
  end,
  sort_by = "insert_at_end",
}

Additional Information

...

commit

c7492a7

andresatierf avatar Jan 19 '23 16:01 andresatierf

I'm not sure I understand this issue very well but FWIW as I've explained in numerous issues the tabs functionality is user maintained and contributed. If there are gaps in the functionality I'm open to PRs but my primary focus is on buffer specific functionality.

akinsho avatar Feb 09 '23 10:02 akinsho

@akinsho If I were right

Note:

  • **{ A }**: A is selected.
  • | B |: B is NOT selected.

The actual behavior:

  • File 1 is selected, tab 1 is selected.

*{ FILE 1 }* | file 2 | *{ 1 }* | 2 |

  • Run :BufferLineMoveNext. Then, file 2 is selected, tab 2 is selected.

| file 1 | *{ file 2 }* | 1 | *{ 2 }*

The expected behavior:

  • File 1 is selected, tab 1 is selected.

*{ FILE 1 }* | file 2 | *{ 1 }* | 2 |

  • Run :BufferLineMoveNext. Then, file 2 is selected, tab 1 is still selected.

| file 1 | *{ file 2 }* *{ 1 }* | 2 |

ansidev avatar Apr 25 '23 22:04 ansidev

@ansidev I never really understood this issue and the OP didn't clarify. Your example doesn't really seem right though since the bufferline move commands would move the positions whereas in your example nothing has moved position.

akinsho avatar Apr 26 '23 07:04 akinsho

@akinsho I guess you didn't read my comment carefully. However, I've updated it for more readable.

The issue, I guess, is with the active tab, it might be caused by mode = "tab".

Of courses, @andresatierf needs to confirm.

ansidev avatar Apr 26 '23 07:04 ansidev

@akinsho @ansidev the problem I was facing is as follows:

  1. I'm in tab 1 and buffer 1
  2. I use :BufferLineMoveNext
  3. I go to tab 2 and the buffers changed there too (buffers 3 and 4)

andresatierf avatar Apr 26 '23 07:04 andresatierf

Ok so this still is very confusing for me so I'll clarify and comment on a few things:

  • The BufferLineMove{Prev,Next} command in buffer mode swaps buffers i.e. if A | B and you run move next on A you will get B | A none of the conversation so far seems to be talking about/pointing this out as what is missing from tabs i.e. Tab 1 | Tab 2 swapping these should give Tab 2 | Tab 1. This is what I understand to be the issue
  • AFAIK from your example @ansidev nothing is being swapped which is why I believe your example does not relate correctly.

So to clarify are we actually talking about moving/swapping the tabs or do you maybe mean just switching current tab?

akinsho avatar Apr 26 '23 08:04 akinsho

I'm sorry for not explaining myself clearly I don't remember the exact setup I had when this occurred but it was something like this:

Tab 1* Tab 2
Buf A* | Buf B Buf C | Buf D

I was on Tab 1 on Buf A and executed :BufferLineMoveNext and ended up with something like this:

Tab 1* Tab 2
Buf B | Buf A* Buf D | Buf C

The problem is that the order was also changed in the inactive tab

andresatierf avatar Apr 26 '23 08:04 andresatierf

Thanks for clarifying well tbh there isn't really an expectation that this would necessarily work. The tab functionality doesn't have feature parity. Looking at the logic it's not immediately clear why the tabs themselves aren't moved rather than the underlying buffers, but literally no one has investigated this or tried to actually implement it so 🤷🏾‍♂️

https://github.com/akinsho/bufferline.nvim/blob/7f99c144ed092d462c82a008a838f19cad6d8c1a/lua/bufferline/commands.lua#L153

akinsho avatar Apr 26 '23 08:04 akinsho

As of now, at least for me when mode = "tabs" is on (which means I don't use buffers as tabs but regular vim tabs) :BufferLineMoveNext throws an error:

Error executing Lua callback: vim/shared.lua:0: Invalid buffer id: 2
stack traceback:
        [C]: at 0x5577a75acf50
        vim/shared.lua: in function 'tbl_map'
        .../nvim/lazy/bufferline.nvim/lua/bufferline/utils/init.lua:171: in function 'save_positions'
        ...re/nvim/lazy/bufferline.nvim/lua/bufferline/commands.lua:163: in function 'move'
        ...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:163: in function <...local/share/nvim/lazy/bufferline.nvim/lua/bufferline.lua:163>

I'm not complaining though, as these regular vim keymaps do work well with bufferline 👍:

-- Tabs move
vim.keymap.set("n", "<t", ":tabmove -1<Return>")
vim.keymap.set("n", ">t", ":tabmove +1<Return>")

serranomorante avatar Aug 27 '23 10:08 serranomorante