feat(buffers): option to show buffer index (#433)

* feature(buffers): option to show buffer indices
This commit is contained in:
Ilya Malyavin 2021-11-13 14:44:35 +01:00 committed by GitHub
parent df46c1e70a
commit d2f5d6c8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View File

@ -421,7 +421,10 @@ sections = {
{ {
'buffers', 'buffers',
show_filename_only = true, -- shows shortened relative path when false 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 max_length = vim.o.columns * 2 / 3, -- maximum width of buffers component
-- can also be a function that returns value of max_length dynamicaly -- can also be a function that returns value of max_length dynamicaly
filetype_names = { filetype_names = {

View File

@ -410,7 +410,10 @@ will be.
{ {
'buffers', 'buffers',
show_filename_only = true, -- shows shortened relative path when false 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 max_length = vim.o.columns * 2 / 3, -- maximum width of buffers component
-- can also be a function that returns value of max_length dynamicaly -- can also be a function that returns value of max_length dynamicaly
filetype_names = { filetype_names = {

View File

@ -48,10 +48,17 @@ end
---@return string ---@return string
function Buffer:render() function Buffer:render()
local name local name
if self.ellipse then -- show elipsis if self.ellipse then -- show elipsis
name = '...' name = '...'
else 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 end
self.len = vim.fn.strchars(name) self.len = vim.fn.strchars(name)

View File

@ -8,6 +8,7 @@ local highlight = require 'lualine.highlight'
local default_options = { local default_options = {
show_filename_only = true, show_filename_only = true,
show_modified_status = true, show_modified_status = true,
mode = 0,
max_length = 0, max_length = 0,
filetype_names = { filetype_names = {
TelescopePrompt = 'Telescope', TelescopePrompt = 'Telescope',