I’m writing a plugin where I’m trying to colorize the statuslines with different colors depending on the file name. However, I’m having troubles setting the highlights. So far I’ve been trying to use nvim_win_set_hl_ns
and used User1…9. Is there a better way? Is it even possible?
I’ve provided a repro-script below. You can run it with nvim --clean -u repro_script.lua
. I want the two status-lines to have red and green text. None of them should have blue.
local function get_line(buf_nbr)
if buf_nbr == 1 then
return "%9*I should be green";
end
if buf_nbr == 2 then
return "%9*I should be red";
end
return "%9*I should be blue";
end
function Status_Line()
local buf_nbr = vim.fn.winbufnr(vim.g.statusline_winid);
return table.concat {
get_line(buf_nbr),
" | buf_nr: " .. buf_nbr
}
end
vim.o.statusline = "%!luaeval('Status_Line()')"
local ns_1_id = vim.api.nvim_create_namespace("one");
local ns_2_id = vim.api.nvim_create_namespace("two");
local ns_3_id = vim.api.nvim_create_namespace("three");
vim.api.nvim_set_hl(ns_1_id, "User9", { ctermfg = "green" });
vim.api.nvim_set_hl(ns_2_id, "User9", { ctermfg = "red" });
vim.api.nvim_set_hl(ns_3_id, "User9", { ctermfg = "blue" });
vim.api.nvim_set_hl_ns(ns_3_id);
local win_1 = vim.api.nvim_get_current_win()
vim.api.nvim_command('botright vnew')
local win_2 = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_hl_ns(win_1, ns_1_id);
vim.api.nvim_win_set_hl_ns(win_2, ns_2_id);