From d2f5d6c8aa5e3e09817a6bc557d73527392c7f11 Mon Sep 17 00:00:00 2001 From: Ilya Malyavin Date: Sat, 13 Nov 2021 14:44:35 +0100 Subject: [PATCH] feat(buffers): option to show buffer index (#433) * feature(buffers): option to show buffer indices --- README.md | 5 ++++- doc/lualine.txt | 5 ++++- lua/lualine/components/buffers/buffer.lua | 9 ++++++++- lua/lualine/components/buffers/init.lua | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3f9570c..983996d 100644 --- a/README.md +++ b/README.md @@ -421,7 +421,10 @@ sections = { { 'buffers', show_filename_only = true, -- shows shortened relative path when false - show_modified_status = true -- shows indicator then bufder is modified + show_modified_status = true -- shows indicator then buffer is modified + mode = 0, -- 0 shows buffer name + -- 1 buffer index (bufnr) + -- 2 shows buffer name + buffer index (bufnr) max_length = vim.o.columns * 2 / 3, -- maximum width of buffers component -- can also be a function that returns value of max_length dynamicaly filetype_names = { diff --git a/doc/lualine.txt b/doc/lualine.txt index 21ca457..fa5c491 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -410,7 +410,10 @@ will be. { 'buffers', show_filename_only = true, -- shows shortened relative path when false - show_modified_status = true -- shows indicator then bufder is modified + show_modified_status = true -- shows indicator then buffer is modified + mode = 0, -- 0 shows buffer name + -- 1 buffer index (bufnr) + -- 2 shows buffer name + buffer index (bufnr) max_length = vim.o.columns * 2 / 3, -- maximum width of buffers component -- can also be a function that returns value of max_length dynamicaly filetype_names = { diff --git a/lua/lualine/components/buffers/buffer.lua b/lua/lualine/components/buffers/buffer.lua index 81ae252..f05c866 100644 --- a/lua/lualine/components/buffers/buffer.lua +++ b/lua/lualine/components/buffers/buffer.lua @@ -48,10 +48,17 @@ end ---@return string function Buffer:render() local name + if self.ellipse then -- show elipsis name = '...' else - name = string.format(' %s%s%s ', self.icon, self:name(), self.modified_icon) + if self.options.mode == 0 then + name = string.format(' %s%s%s ', self.icon, self:name(), self.modified_icon) + elseif self.options.mode == 1 then + name = string.format(' %s %s%s ', self.bufnr, self.icon, self.modified_icon) + else + name = string.format(' %s %s%s%s ', self.bufnr, self.icon, self:name(), self.modified_icon) + end end self.len = vim.fn.strchars(name) diff --git a/lua/lualine/components/buffers/init.lua b/lua/lualine/components/buffers/init.lua index 96d6f63..1500d34 100644 --- a/lua/lualine/components/buffers/init.lua +++ b/lua/lualine/components/buffers/init.lua @@ -8,6 +8,7 @@ local highlight = require 'lualine.highlight' local default_options = { show_filename_only = true, show_modified_status = true, + mode = 0, max_length = 0, filetype_names = { TelescopePrompt = 'Telescope',