nvim-lualine / lualine.nvim

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

Feat: Show tab number by default unless the tab is renamed #1216

Closed ckangnz closed 3 months ago

ckangnz commented 3 months ago

Requested feature

When I create a new tab, I want the tab to show an icon with tab number 󰓩 1. But when I rename the tab using :lualineRenameTab, I want it to show 󰓩 RenamedTab

      lualine_y = {
        {
          'tabs',
          max_length = vim.o.columns,
          separator = { left = '', right = '' },
          use_mode_colors = true,
          mode = 1,
          tabs_color = {
            active = 'lualine_a_insert',
            inactive = 'lualine_b_normal',
          },
          show_modified_status = false,
          fmt = function(name, context)
            return '󰓩  ' .. name .. ' ' .. context.tabnr
          end

        },
      },

Motivation

It's visually distracting to see the file name on my tab bar when I can already see it in windows. So I want to remove the texts from my tabs. But when I work on multiple projects on each tab, I want to to rename my tabs so that it's easy to identify which project i'm on.

ckangnz commented 3 months ago

Found a solution on my own 🙂

Here is an example of what i've done if anyone is interested

          fmt = function(name, context)
            if vim.bo.filetype == 'TelescopePrompt' then
              return '🔍Searching...'
            elseif vim.startswith(name, 'fugitive:') then
              return ''
            elseif vim.startswith(name, 'Merginal:branchlist') then
              return ' Branches'
            elseif vim.endswith(name, '--graph --all') then
              return ' GV'
            elseif vim.bo.filetype == 'qf' then
              return '󰁨 quickfix'
            elseif vim.bo.filetype == 'oil' then
              return '📂 Files'
            elseif vim.bo.filetype == 'octo' then
              return ' Pull Request'
            elseif vim.bo.filetype == 'octo_panel' then
              return ' PR Review'
            elseif vim.bo.filetype == 'vim-plug' then
              return '🧩 Vim Plug'
            elseif name == '[No Name]' then
              return '📄 New file'
            elseif name == vim.fn.expand('%:t') then
              return '󰓩  ' .. context.tabnr
            end
            return '󰓩  ' .. name
          end