nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.93k stars 462 forks source link

Feat: Add icon to `filename` component #656

Closed tapyu closed 2 years ago

tapyu commented 2 years ago

Requested feature

An option to filename component that allows displaying the filetype icon along with the name. With the current components, the best that I could achieve was the following:

Screenshot from 2022-04-18 05-47-27

It is a reasonable result, but the file name and the type icon are kind of distant... Furthermore, I had to disable the file status option, otherwise it would be in the middle...

Motivation

In my humble opinion, filename and filetype carry very close meanings and could be displayed together, as I tried to do with the available components.

setup

local is_status_ok, lualine = pcall(require, "lualine")
if not is_status_ok then
  return
end

lualine.setup {
  options = {
    icons_enabled = true,
    theme = 'codedark',
    component_separators = { left = '', right = ''},
    section_separators = { left = '', right = ''},
    disabled_filetypes = {},
    always_divide_middle = true,
    globalstatus = false,
  },
  sections = {
    lualine_a = {'mode'},
    lualine_b = {'branch', 'diff', 'diagnostics'},
    lualine_c = {{'filename', file_status = false, separator = ''}, {'filetype', icon_only = true}},
    lualine_x = {'encoding', 'fileformat'},
    lualine_y = {'progress'},
    lualine_z = {'location'}
  },
  inactive_sections = {
    lualine_a = {},
    lualine_b = {},
    lualine_c = {'filename'},
    lualine_x = {'location'},
    lualine_y = {},
    lualine_z = {}
  },
  tabline = {},
  extensions = {}
}
shadmansaleh commented 2 years ago

You can put the fitletype icon in front of filename and also can control the spacing with padding option. You're quite close actually .

-    lualine_c = {{'filename', file_status = false, separator = ''}, {'filetype', icon_only = true}},
+    lualine_c = {{'filetype', icon_only = true, separator = '', padding={right=0, left=1}}, 'filename' },
tapyu commented 2 years ago

I thought just setting the padding to zero wouldn't be enough. Now it looks fine. Thanks.