如何将Harpoon的删除标记与缓冲区函数迁移至Harpoon2?
适配Harpoon2的标记移除+缓冲区删除函数实现
原Harpoon 1.x的函数实现了移除当前文件的Harpoon标记+删除对应缓冲区的功能,以下是适配Harpoon2的实现方案:
迁移后的完整代码
function() local harpoon = require('harpoon') local default_list = harpoon:list() local current_index = default_list:get_current_index() if current_index ~= nil then default_list:remove(current_index) -- 若tabline未自动更新,可手动触发:harpoon:update_tabline() end require('mini.bufremove').delete(0, true) end
关键API变化说明
- API风格切换:Harpoon2采用面向对象式API,通过
harpoon:list()获取默认标记列表(如需操作自定义列表,可传入列表名称,如harpoon:list('my-custom-list')) - 获取当前标记索引:替换原
require("harpoon.mark").get_current_index()为default_list:get_current_index() - 移除标记:无需手动修改配置表,直接调用
default_list:remove(current_index),Harpoon2会自动处理标记的持久化与状态同步 - Tabline更新:Harpoon2默认会在标记变更后自动更新tabline,原代码中的
vim.cmd("redrawt")可移除;若遇到tabline不刷新的异常情况,可添加harpoon:update_tabline()手动触发更新 - 缓冲区删除逻辑:
mini.bufremove的API未发生变化,保持原逻辑即可
内容的提问来源于stack exchange,提问作者rofrol
相关产品推荐
相关产品推荐

