Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I want to add icon in default statusline without using statusline plugin because if i used it will take longer for open file

You must be logged in to vote

This's a fairly open-ended question but here's what I can tell you:

  1. statusline plugins are usually pretty optimized and shouldn't slowdown opening files
  2. adding the icon is pretty much replicating what a statusline plugin does but on a smaller scale

here're some examples if you want to get started:

  • Easiest, but has unnecessary updates :
vim.o.statusline = [[%<%f %{luaeval('require"nvim-web-devicons".get_icon_by_filetype(vim.bo.filetype)')}%h%m%r%=%-14.(%l,%c%V%) %P]]
  • Less updates, but slightly more complicated:
vim.api.nvim_create_autocmd("BufEnter", {
    callback = function ()
    vim.o.statusline =
    "%<%f "..
    require"nvim-web-devicons".get_icon_by_filetype(vim.bo.filetype)..

Replies: 2 comments · 1 reply

Comment options

This's a fairly open-ended question but here's what I can tell you:

  1. statusline plugins are usually pretty optimized and shouldn't slowdown opening files
  2. adding the icon is pretty much replicating what a statusline plugin does but on a smaller scale

here're some examples if you want to get started:

  • Easiest, but has unnecessary updates :
vim.o.statusline = [[%<%f %{luaeval('require"nvim-web-devicons".get_icon_by_filetype(vim.bo.filetype)')}%h%m%r%=%-14.(%l,%c%V%) %P]]
  • Less updates, but slightly more complicated:
vim.api.nvim_create_autocmd("BufEnter", {
    callback = function ()
    vim.o.statusline =
    "%<%f "..
    require"nvim-web-devicons".get_icon_by_filetype(vim.bo.filetype)..
    "%h%m%r%=%-14.(%l,%c%V%) %P"
    end
})
You must be logged in to vote
0 replies
Answer selected by DinkyTrady
Comment options

@T-727 and how to change color?

You must be logged in to vote
1 reply
@T-727
Comment options

You can add a highlight group to the statusline by adding %#group_name#,
then update the color of it with the icon.
Here's what I mean using the second example:

vim.cmd "hi StatuslineIcon gui=reverse"
vim.api.nvim_create_autocmd("BufEnter", {
    callback = function()
        local icon, color = require "nvim-web-devicons".get_icon_color_by_filetype(vim.bo.filetype)
        vim.cmd("hi StatuslineIcon guibg=" .. color)
        vim.o.statusline =
        "%<%f %#StatuslineIcon#" ..
        icon ..
        "%##%h%m%r%=%-14.(%l,%c%V%) %P"
    end
})

You can type :h statusline for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #163 on October 04, 2022 13:13.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.