How to shorten the branch name to 40 characters if not enough space? #894
Answered
by
fitrh
alexventuraio
asked this question in
Q&A
-
The branch name is taking most of the space available within the split and even the filename is not being shown. I would prefer to shorten the branch name to the last 40 characters only and have the file name visible, is there a way to achieve that? This is my current configlualine.setup({
options = {
icons_enabled = true,
theme = 'powerline',
disabled_filetypes = { 'NvimTree' },
component_separators = { left = '', right = '' },
section_separators = { left = '', right = '' },
},
sections = {
lualine_b = {
'branch',
{
'diff',
colored = true, -- Displays a colored diff status if set to true
diff_color = {
-- Same color values as the general color option can be used here.
added = 'DiffAdd', -- Changes the diff's added color
modified = 'DiffChange', -- Changes the diff's modified color
removed = 'DiffDelete', -- Changes the diff's removed color you
},
},
'diagnostics'
},
lualine_c = {
{
'filename',
file_status = true, -- Displays file status (readonly status, modified status)
newfile_status = true, -- Display new file status (new file means no write after created)
full_path = true, -- 1: Relative path
path = 1,
}
},
},
inactive_sections = {
lualine_c = {
{
'filename',
file_status = true, -- Displays file status (readonly status, modified status)
newfile_status = true, -- Display new file status (new file means no write after created)
full_path = true, -- 1: Relative path
path = 1,
}
},
},
}) |
Beta Was this translation helpful? Give feedback.
Answered by
fitrh
Nov 21, 2022
Replies: 2 comments 3 replies
-
local function get_branch()
require("lualine.components.branch.git_branch").init()
local branch = require("lualine.components.branch.git_branch").get_branch()
return string.sub(branch, 1, 40)
end lualine_b = {
get_branch,
{
'diff',
colored = true, -- Displays a colored diff status if set to true
diff_color = {
-- Same color values as the general color option can be used here.
added = 'DiffAdd', -- Changes the diff's added color
modified = 'DiffChange', -- Changes the diff's modified color
removed = 'DiffDelete', -- Changes the diff's removed color you
},
},
'diagnostics'
}, |
Beta Was this translation helpful? Give feedback.
1 reply
-
You can use the {
"branch",
fmt = function(str)
if vim.api.nvim_strwidth(str) > 40 then
return ("%s…"):format(str:sub(1, 39))
end
return str
end,
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
alexventuraio
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the
fmt
component options