rebelot / heirline.nvim

Heirline.nvim is a no-nonsense Neovim Statusline plugin designed around recursive inheritance to be exceptionally fast and versatile.
MIT License
1.02k stars 40 forks source link

"ShowCmd" doesn't work without using "vim.opt.showcmdloc" option #143

Closed isaif closed 1 year ago

isaif commented 1 year ago

I think docs doesn't mention adding the option of vim.opt.showcmdloc = 'statusline', without which "ShowCmd" doesn't work.

Here is a minimal config using lazy.nvim

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    {
        "rebelot/heirline.nvim",
        init = function()
            vim.opt.cmdheight = 0
            -- vim.opt.showcmdloc = "statusline"
        end,
        config = function()
            local heirline = require("heirline")
            local conditions = require("heirline.conditions")
            local utils = require("heirline.utils")

            local FileNameBlock = {
                init = function(self)
                    self.filename = vim.api.nvim_buf_get_name(0)
                end,
                condition = conditions.buffer_not_empty,
            }

            local FileName = {
                provider = function(self)
                    local filename = vim.fn.fnamemodify(self.filename, ":~:.")
                    if filename == "" then
                        return "[No Name]"
                    end
                    if not conditions.width_percent_below(#filename, 0.25) then
                        filename = vim.fn.pathshorten(filename)
                    end
                    return filename
                end,
            }

            local FileFlags = {
                {
                    condition = function()
                        return vim.bo.modified
                    end,
                    provider = " [+] ",
                },
                {
                    condition = function()
                        return not vim.bo.modifiable or vim.bo.readonly
                    end,
                    provider = "",
                },
            }

            FileNameBlock = utils.insert(FileNameBlock, FileName, unpack(FileFlags), { provider = "%< " })

            local ShowCmd = {
                condition = function()
                    return vim.o.cmdheight == 0
                end,
                provider = ":%3.5(%S%)",
            }

            local StatusLine = {
                ShowCmd,
                FileNameBlock,
            }

            heirline.setup({ statusline = StatusLine })
        end,
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})