WinBarSeparator, WinBarContext, and WinBarFilename 是用来显示自定义的高亮。
在代码中我们使用nvim-navic插件来帮助我们获取代码的上下文更详细的信息。
高亮配置
为了更好地显示窗口样式,我们可以通过修改winbar提供的高亮组样式来修改winbar的样式。
WinBar 用来配置当前窗口的样式
WinBarNC 用来配置非当前窗口样式。
主要代码
local M ={}
local colors = require "config.colors"
local navic = require "nvim-navic"
local utils = require "utils"
local icons = require "config.icons"
vim.api.nvim_set_hl(0,"WinBarSeparator",{ fg = colors.grey})
vim.api.nvim_set_hl(0,"WinBarFilename",{ fg = colors.green, bg = colors.grey})
vim.api.nvim_set_hl(0,"WinBarContext",{ fg = colors.green, bg = colors.grey})
M.winbar_filetype_exclude={"help","startify","dashboard","packer","neogitstatus","NvimTree","Trouble","alpha","lir","Outline","spectre_panel","toggleterm",}
local excludes = function()
if vim.tbl_contains(M.winbar_filetype_exclude, vim.bo.filetype) then
vim.opt_local.winbar= nil
return true
end
return false
end
local function get_modified()
if utils.get_buf_option"mod" then
local mod = icons.git.Mod
return "%#WinBarFilename#" .. mod .. " " .. "%t" .. "%*"
end
return "%#WinBarFilename#" .. "%t" .. "%*"
end
local function get_location()
local location = navic.get_location()
if not utils.is_empty(location) then
return "%#WinBarContext#" .. " " .. icons.ui.ChevronRight .. " " .. location .. "%*"
end
return ""
end
function M.get_winbar()
if excludes() then
return ""
end
if navic.is_available() then
return "%#WinBarSeparator#"
.. "%="
.. ""
.. "%*"
.. get_modified()
.. get_location()
.. "%#WinBarSeparator#"
.. ""
.. "%*"
else
return "%#WinBarSeparator#" .. "%=" .. "" .. "%*" .. get_modified() .. "%#WinBarSeparator#" .. "" .. "%*"
end
end
return M