incline.nvim
incline.nvim copied to clipboard
How to add filetype icon like in the screenshot?
In the screenshot in the README each incline statusline has a filetype icon next to it which looks super neat. How do I achieve this? I couldn't find anything in the docs.
you can use nvim-web-devicons for this, and override your render method.
I do more things in my config, but the basic idea should be visible.
Thank you for your answer. Your solution doens't seem to provide colored icons like in the screenshot in the README. Do you know how I could achieve that? I would personally think it was neat if incline came with colored file icons out of the box, have you considered doing that? :)
@melkster Hi, if you still interested.
For the highlight, you can take a look at :help incline-render. there is an example that provides groups highlighting.
Currently, I've add red modified icon to rendering when buffer changed.

You can take a look at my config
And normally nvim-web-devicons already provides icon colors, you can get the icon and color code then constructs a table with highlighting args to passing to incline.
Thanks! I managed to throw this solution together to anyone else that wants to achieve the same thing:
require('incline').setup({
render = function(props)
local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ':t')
local icon, color = require('nvim-web-devicons').get_icon_color(filename)
return {
{ icon, guifg = color },
{ ' ' },
{ filename },
}
end
})
Perhaps this could be added as a second render configuration example to the helpdocs, or used as the default renderer after checking that nvim-web-devicons is installed?
For those who want diagnostic info in incline, you can use the code below.
This will replace the filetype icon with the highest severity diagnostic icon if diagnostics exist for the project.
You can modify this to be buffer specific instead of project wide by specifying the buffer parameter in vim.diagnostic.get().
Filetype icons require nvim-web-devicons.
local get_icon_color = require("nvim-web-devicons").get_icon_color
local get_buf_option = vim.api.nvim_buf_get_option
local diagnostic_map = {}
diagnostic_map[vim.diagnostic.severity.ERROR] = { "✗", guifg = "red" }
diagnostic_map[vim.diagnostic.severity.WARN] = { "!", guifg = "orange" }
diagnostic_map[vim.diagnostic.severity.INFO] = { "", guifg = "green" }
diagnostic_map[vim.diagnostic.severity.HINT] = { "", guifg = "blue" }
local function get_highest_diagnostic_severity(diagnostics)
local highest_severity = 100
for _, diagnostic in ipairs(diagnostics) do
local severity = diagnostic.severity
if severity < highest_severity then
highest_severity = severity
end
end
return highest_severity
end
local function get_status(filename)
local diagnostics = vim.diagnostic.get()
if vim.tbl_count(diagnostics) > 0 then
local highest_severity = get_highest_diagnostic_severity(diagnostics)
return diagnostic_map[highest_severity]
else
local filetype_icon, color = get_icon_color(filename)
return { filetype_icon, guifg = color }
end
end
require("incline").setup({
debounce_threshold = { falling = 500, rising = 250 },
render = function(props)
local bufname = vim.api.nvim_buf_get_name(props.buf)
local filename = vim.fn.fnamemodify(bufname, ":t")
local status = get_status(filename)
local modified = get_buf_option(props.buf, "modified") and "⦁" or ""
return {
status,
{ " " },
{ filename },
{ " " },
{ modified, guifg = "grey" },
}
end,
})
@mystilleef I love this, would you like to share a screenshot along with your code in the Showcase?
@b0o Yes, feel free to share it. I'll make screenshots tomorrow, or feel free to make them on my behalf if you want. Fantastic work by the way. This is the second plugin of yours that I use. :-)