-
Notifications
You must be signed in to change notification settings - Fork 3
Tips
Jiahe Jiang edited this page Oct 14, 2024
·
7 revisions
vim.g.neominimap = {
buf_filter = function(bufnr)
local line_count = vim.api.nvim_buf_line_count(bufnr)
return line_count < 4096
end
}
-- Refresh all windows in current tab when focus switched
vim.api.nvim_create_autocmd("WinEnter", {
group = vim.api.nvim_create_augroup("minimap", { clear = true }),
pattern = "*",
callback = function()
require("neominimap").tabRefresh({}, {})
end,
})
vim.g.neominimap = {
layout = "float",
win_filter = function(winid)
return winid == vim.api.nvim_get_current_win()
end,
}
vim.g.neominimap = {
winopt = function (opt, winid)
opt.signcolumn = 'yes:1'
end
}
Integrating with statuscol
First, in the neominimap
configuration, set mode = "sign"
for the handlers
that you want to display in the sign column.
For example:
vim.g.neominimap = {
auto_enable = true,
diagnostic = {
mode = "line",
},
git = {
enabled = true,
mode = "sign",
},
search = {
enabled = true,
mode = "sign",
},
}
Next, define a wrapper function to safely invoke StatusCol
.
_G.MyStatusCol = function()
local ok, _ = pcall(require, "statuscol") -- Make sure statuscol is installed and loaded.
if ok then
-- For latest
-- return statuscol.get_statuscol_string()
-- For version 0.10
return _G.StatusCol()
else
return ""
end
end
vim.g.neominimap = {
winopt = function(wo)
wo.statuscolumn = "%!v:lua.MyStatusCol()"
end
}
Finally, filter out segments for normal buffers and minimap buffers.
Here is an example:
local function is_neominimap(arg)
return vim.bo[arg.buf].filetype == "neominimap"
end
local function is_not_neominimap(arg)
return not is_neominimap(arg)
end
return {
"luukvbaal/statuscol.nvim",
opts = function()
local builtin = require("statuscol.builtin")
return {
setopt = true,
relculright = true,
segments = {
-- These segments will be shown for normal buffers
{
sign = {
namespace = { ".*" },
name = { ".*" },
},
condition = { is_not_neominimap },
},
{
text = {
builtin.lnumfunc,
" ",
builtin.foldfunc,
},
condition = { is_not_neominimap },
},
{
sign = {
namespace = { "gitsigns_" },
},
condition = { is_not_neominimap },
},
-- These segments will be shown for minimap buffers
{
sign = {
namespace = { "neominimap_search" },
maxwidth = 1,
colwidth = 1, -- For more compact look
},
condition = { is_neominimap },
},
{
sign = {
namespace = { "neominimap_git" },
maxwidth = 1,
colwidth = 1,
},
condition = { is_neominimap },
},
},
}
end,
}
Use key events to toggle the minimap window on and off during search navigation.
vim.on_key(function(char)
if vim.fn.mode() == "n" then
local is_search_nav_key = vim.tbl_contains({ "<CR>", "n", "N", "*", "#", "?", "/" }, vim.fn.keytrans(char))
if is_search_nav_key then
vim.g.neominimap_is_in_search = true
require("neominimap").winRefresh({}, {})
else
vim.g.neominimap_is_in_search = false
require("neominimap").winRefresh({}, {})
end
end
end, vim.api.nvim_create_namespace("auto_search_nav"))
Set up neominimap
configuration like this:
vim.g.neominimap = {
auto_enable = true,
win_filter = function(bufnr)
return vim.g.neominimap_is_in_search
end,
layout = "float",
search = {
enabled = true,
mode = "line",
},
}