LunarVim / Neovim-from-scratch

📚 A Neovim config designed from scratch to be understandable
https://www.chrisatmachine.com/
GNU General Public License v3.0
5.31k stars 1.18k forks source link

The lualine and NvimTree plugin has a problem. #330

Closed RobertMiguel closed 1 month ago

RobertMiguel commented 4 months ago

When only NvimTree is open, lualina disappears, and only returns when I open a file again. I thought it was NvimTree itself, but I checked and changed some things until the default configuration remained and the problem appeared again, can anyone help me?

My file :

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

local hide_in_width = function()
    return vim.fn.winwidth(0) > 80
end

local diagnostics = {
    "diagnostics",
    sources = { "nvim_diagnostic" },
    sections = { "error", "warn" },
    symbols = { error = " ", warn = " " },
    colored = false,
    update_in_insert = false,
    always_visible = true,
}

local diff = {
    "diff",
    colored = false,
    symbols = { added = " ", modified = " ", removed = " " }, -- changes diff symbols
  cond = hide_in_width
}

local mode = {
    "mode",
    fmt = function(str)
        return "-- " .. str .. " --"
    end,
}

local filetype = {
    "filetype",
    icons_enabled = false,
    icon = nil,
}

local branch = {
    "branch",
    icons_enabled = true,
    icon = "",
}

local location = {
    "location",
    padding = 0,
}

-- cool function for progress
local progress = function()
    local current_line = vim.fn.line(".")
    local total_lines = vim.fn.line("$")
    local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
    local line_ratio = current_line / total_lines
    local index = math.ceil(line_ratio * #chars)
    return chars[index]
end

local spaces = function()
    return "spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth")
end

lualine.setup({
    options = {
        icons_enabled = true,
        theme = "auto",
        component_separators = { left = "", right = "" },
        section_separators = { left = "", right = "" },
        disabled_filetypes = { "alpha", "dashboard", "NvimTree", "Outline" },
        always_divide_middle = true,
    },
    sections = {
        lualine_a = { branch, diagnostics },
        lualine_b = { mode },
        lualine_c = {},
        -- lualine_x = { "encoding", "fileformat", "filetype" },
        lualine_x = { diff, spaces, "encoding", filetype },
        lualine_y = { location },
        lualine_z = { progress },
    },
    inactive_sections = {
        lualine_a = {},
        lualine_b = {},
        lualine_c = { "filename" },
        lualine_x = { "location" },
        lualine_y = {},
        lualine_z = {},
    },
    tabline = {},
    extensions = {},
})

This is the same configuration in the repository.

notoyz commented 1 month ago

In the lualine.setup options you have the line:

disabled_filetypes = { "alpha", "dashboard", "NvimTree", "Outline" },

Remove "NvimTree", if you want lualine to remain visible when you enter NvimTree

RobertMiguel commented 1 month ago

Thank you very much man, thank you it worked!

notoyz commented 1 month ago

Another thing I've noticed, you probably want to change the line

return "spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth")

and replace it with

return "spaces: " .. vim.api.nvim_get_option_value("shiftwidth", { buf = 0 })

this is because vim.api.nvim_buf_get_option will soon be deprecated. I just had to change this myself so thought I'd give you the heads up.