We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Just thought if anyone wanted to have pinned buffers map to harpoon, this would be helpful
return { "romgrk/barbar.nvim", dependencies = { "ThePrimeagen/harpoon" }, config = function() local barbar = require("barbar") local state = require("barbar.state") local render = require("barbar.ui.render") local harpoon = require("harpoon") barbar.setup({ hide = { inactive = true, }, icons = { pinned = { filename = true, buffer_index = true }, diagnostics = { { enabled = true } }, }, }) local function unpin_all() for _, buf in ipairs(state.buffers) do local data = state.get_buffer_data(buf) data.pinned = false end end local function get_buffer_by_mark(mark) for _, buf in ipairs(vim.api.nvim_list_bufs()) do local buffer_path = vim.api.nvim_buf_get_name(buf) if buffer_path == "" or mark.value == "" then goto continue end local mark_pattern = mark.value:gsub("([%(%)%.%%%+%-%*%?%[%]%^%$])", "%%%1") if string.match(buffer_path, mark_pattern) then return buf end local buffer_path_pattern = buffer_path:gsub("([%(%)%.%%%+%-%*%?%[%]%^%$])", "%%%1") if string.match(mark.value, buffer_path_pattern) then return buf end ::continue:: end end local function refresh_all_harpoon_tabs() local list = harpoon:list() unpin_all() for _, mark in ipairs(list.items) do local buf = get_buffer_by_mark(mark) if buf == nil then vim.cmd("badd " .. mark.value) buf = get_buffer_by_mark(mark) end if buf ~= nil then state.toggle_pin(buf) end end render.update() end vim.api.nvim_create_autocmd({ "BufEnter", "BufAdd", "BufLeave", "User" }, { callback = refresh_all_harpoon_tabs, }) end, }
The text was updated successfully, but these errors were encountered:
One other note, I have my harpoon add call the "User" autocmd to update the tabs
vim.keymap.set("n", "<leader>pa", function() harpoon:list():add() vim.cmd(":do User") end, { desc = "Harpoon: Add file" })
Sorry, something went wrong.
It might be better not to use ipairs to handle harpoon item deletion. ipairs stops at nil value.
local function refresh_all_harpoon_tabs() local list = harpoon:list() unpin_all() for i = 1, list:length() do local mark = list.items[i] if mark == nil then goto continue end local buf = get_buffer_by_mark(mark) if buf == nil then vim.cmd("badd " .. mark.value) buf = get_buffer_by_mark(mark) end if buf ~= nil then state.toggle_pin(buf) end ::continue:: end render.update() end
amalavet
No branches or pull requests
Just thought if anyone wanted to have pinned buffers map to harpoon, this would be helpful
The text was updated successfully, but these errors were encountered: