-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
shift buffer to left / right ( tabufline ) #8
Comments
ok i'll add some functions for this in sept |
Thank you, I am willing to actively cooperate with the test |
or you can make your own functions for this :)) |
So in the above image, init.lua is at index 1 , stylua at index 2 and so on. gitignore file's buffer name is 5 |
local move_buf_left = function()
local bufs = vim.t.bufs
for index, bufnr in ipairs(bufs) do
if bufnr == vim.api.nvim_get_current_buf() then
if index == 1 then
bufs[1] = bufs[#bufs]
bufs[#bufs] = bufnr
else
bufs[index] = bufs[index - 1]
bufs[index - 1] = bufnr
end
break
end
end
vim.t.bufs = bufs
vim.cmd "redrawtabline"
end make a command out of it & test it |
i will clean the function later |
ok,I'll give it a try |
vim.t.bufs not fond |
do you use nvchad's tabufline? and what did you do till now |
I bound it to a keymap |
I will study again |
Can be used normally local M = {}
function moveAllEleTest(originTbl, n)
if type(originTbl) ~= "table" then
return
end
if #originTbl == 0 then
return
end
local newTbl = {}
for i = 1, #originTbl do
newTbl[i] = originTbl[(n - 1 + i) % #originTbl + 1]
end
return newTbl
end
M.move_buf_left = function()
local bufs = vim.t.bufs
bufs = moveAllEleTest(bufs, 1)
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
M.move_buf_right = function()
local bufs = vim.t.bufs
bufs = moveAllEleTest(bufs, -1)
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
return M
|
hmm then if it works for u, i'll close this issue. |
ok |
thank you |
local M = {}
function moveItemRight(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
print(v)
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == #originTbl + 1 then
table.insert(originTbl, 1, n)
else
table.insert(originTbl, index + 1, n)
end
return originTbl
end
function moveItemLeft(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == 1 then
table.insert(originTbl, #originTbl + 1, n)
else
table.insert(originTbl, index - 1, n)
end
return originTbl
end
M.move_buf_left = function()
local bufs = vim.t.bufs
bufs = moveItemLeft(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
M.move_buf_right = function()
local bufs = vim.t.bufs
bufs = moveItemRight(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
return M
|
nice! |
@siduck I think it would be nice to implement @kola-web's implementation right into (I can make a PR, if you like, let me know. I would also like to suggest to re-open this issue for the implementation of such) |
@martin-braun agreed, however i'll try to make the function small, i'll push today |
@siduck it's not on main yet, is it? |
oh oops! i totally forgot about it, i'll push it in main tomorrow. A lil busy these days! |
@siduck No worries :) Thanks a lot! |
really sorry for the delay, its been added now! |
@siduck Thanks, however, the logic still misbehaves on the edges when trying to move further after it's rolling over: M.tabufline = {
n = {
["<C-j>"] = {
function()
require("nvchad_ui.tabufline").tabuflineNext()
end, "goto next buffer",
},
["<C-S-j>"] = {
function()
require("nvchad_ui.tabufline").move_buf(1)
end, "move buffer forward",
},
["<C-k>"] = {
function()
require("nvchad_ui.tabufline").tabuflinePrev()
end,
"goto prev buffer",
},
["<C-S-k>"] = {
function()
require("nvchad_ui.tabufline").move_buf(-1)
end,
"move buffer backwards",
},
["<leader>c"] = {
function()
require("nvchad_ui.tabufline").close_buffer()
end,
"close buffer",
},
},
} You cannot just do Instead use However, if you choose to provide a variable My suggestion was to simply implement two functions instead ( Please tell me what you think. :) |
@martin-braun hmm i thought it was normal to swap out indexes |
@siduck @martin-braun This is the move method I'm using now, I don't know how to make this streamlined without this problem local M = {}
function moveItemRight(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
print(v)
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == #originTbl + 1 then
table.insert(originTbl, 1, n)
else
table.insert(originTbl, index + 1, n)
end
return originTbl
end
function moveItemLeft(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == 1 then
table.insert(originTbl, #originTbl + 1, n)
else
table.insert(originTbl, index - 1, n)
end
return originTbl
end
M.move_buf_left = function()
local bufs = vim.t.bufs
bufs = moveItemLeft(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
M.move_buf_right = function()
local bufs = vim.t.bufs
bufs = moveItemRight(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
return M
|
whats the problem? @kola-web |
Left and right movements are not in sequence |
oh yea, i probably forgot to push the fix. Will catch up tonight! |
thanks for your effort |
@martin-braun @kola-web ok it should be fixed now! |
@siduck Is it possible to reopen this question |
@kola-web why loop? |
repeated calls require("nvchad_ui.tabufline").move_buf(1) Tab order is shuffled |
you cant use it that way at the moment |
@kola-web i tested it now, it works well vid.mp4 |
Thanks a lot for your work, I'll test it again |
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem was.
Describe the solution you'd like
Like bufferline.nvim's BufferLineMoveNext & BufferLineMovePrev commands
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Screenshot
Maybe a screenshot of the feature
The text was updated successfully, but these errors were encountered: