Skip to content

Commit

Permalink
feat: Improved lualine
Browse files Browse the repository at this point in the history
  • Loading branch information
Allaman committed Mar 20, 2024
1 parent 46f5c2f commit 411d1f4
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions lua/core/plugins/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local default_options = {
-- 4: Filename and parent dir, with tilde as the home directory
},
},
lualine_x = { "encoding", "fileformat", "filetype" },
lualine_x = { "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" },
},
Expand Down Expand Up @@ -53,15 +53,15 @@ local function default_config_function(opts)
}
end

-- Show info when recording a macro
local function is_macro_recording()
local reg = vim.fn.reg_recording()
if reg == "" then
return ""
end
return "Recording to " .. reg
return "Rec to " .. reg
end

-- Show info when recording a macro
table.insert(opts.sections.lualine_x, 1, {
is_macro_recording,
color = { fg = "red", gui = "italic" },
Expand All @@ -70,6 +70,59 @@ local function default_config_function(opts)
end,
})

-- Don't display if encoding is UTF-8
local function encoding()
local ret, _ = (vim.bo.fenc or vim.go.enc):gsub("^utf%-8$", "")
return ret
end

table.insert(opts.sections.lualine_x, 1, {
encoding,
cond = function()
return encoding() ~= ""
end,
})

-- Don't display if fileformat is unix
local function fileformat()
local ret, _ = vim.bo.fileformat:gsub("^unix$", "")
return ret
end

table.insert(opts.sections.lualine_x, 1, {
fileformat,
cond = function()
return fileformat() ~= ""
end,
})

local function wordCount()
local wc = vim.fn.wordcount()
if wc == nil then
return ""
end
if wc["visual_words"] then -- text is selected in visual mode
return wc["visual_words"] .. " Words/" .. wc["visual_chars"] .. " Chars (Vis)"
else -- all of the document
return wc["words"] .. " Words"
end
end

table.insert(opts.sections.lualine_y, 1, {
wordCount,
cond = function()
local ft = vim.opt_local.filetype:get()
local count = {
latex = true,
tex = true,
text = true,
markdown = true,
vimwiki = true,
}
return count[ft] ~= nil
end,
})

require("lualine").setup(opts)
end

Expand Down

0 comments on commit 411d1f4

Please sign in to comment.