My Neovim Plugins #9 — lualine.nvim

lualine.nvim is one of the plugins, where I did a lot of configuration and like how it works. It is there and doesn't stand in my way.

I use 5 sections. On the left, the current mode I'm in. (Normal|Insert|Visual|Replace) followed by the file type icon provided by web-devicons. In the center is the filename with the relative path. On the right are diagnostics, to see quickly if there are warnings or errors in the file. The file format is following the diagnostics and I can't remember, why I have them there. Maybe a legacy. 😅 As last, some information, where my cursor in the file is.

On top, I've also added my custom colorscheme to lualine.

It's simple and enough for me. 😎

Config

return {
	"nvim-lualine/lualine.nvim",
	dependencies = {
		"kyazdani42/nvim-web-devicons",
		{ dir = "~/workspace/kong" },
	},
	config = function()
		local theme = require("kong.colors")
		local custom_fname = require("lualine.components.filename"):extend()
		local highlight = require("lualine.highlight")
		local default_status_colors = { saved = theme.g50, modified = theme.special }

		function custom_fname:init(options)
			custom_fname.super.init(self, options)
			self.status_colors = {
				saved = highlight.create_component_highlight_group(
					{ fg = default_status_colors.saved },
					"filename_status_saved",
					self.options
				),
				modified = highlight.create_component_highlight_group(
					{ fg = default_status_colors.modified },
					"filename_status_modified",
					self.options
				),
			}
			if self.options.color == nil then
				self.options.color = ""
			end
		end

		function custom_fname:update_status()
			local data = custom_fname.super.update_status(self)
			data = highlight.component_format_highlight(
				vim.bo.modified and self.status_colors.modified or self.status_colors.saved
			) .. data
			return data
		end

		require("lualine").setup({
			options = {
				theme = "kong",
				section_separators = "",
				component_separators = "",
				globalstatus = true,
			},
			sections = {
				lualine_a = { "mode" },
				lualine_b = {
					{
						"filetype",
						colored = false,
						icon_only = true,
						padding = { left = 2, right = 2 },
					},
				},
				lualine_c = {
					"%=",
					{
						custom_fname,
						file_status = true,
						path = 1,
					},
				},
				lualine_x = { "diff", "diagnostics" },
				lualine_y = {
					{
						"fileformat",
						padding = { left = 2, right = 2 },
					},
				},
				lualine_z = { "progress", "location" },
			},
		})
	end,
}

78 of #100DaysToOffload

#log #neovim

Thoughts? Discuss...