基于lualine的提供的官方示例修改
nvim主题(当前主题使用的是catpuccin主题)效果图

1-- -- Eviline config for lualine
2-- -- Author: shadmansaleh
3-- -- Credit: glepnir
4-- -- Color table for highlights
5-- -- stylua: ignore
6return {
7 "nvim-lualine/lualine.nvim",
8 event = "VeryLazy",
9 opts = function(_, opts)
10 local palettes = require("catppuccin.palettes").get_palette(vim.o.background == "dark" and "macchiato" or "latte")
11
12 local colors = {
13 inactive_fg = palettes.surface1,
14 inactive_bg = palettes.overlay0,
15 bg = palettes.base,
16 fg = palettes.surface0,
17 yellow = "#ECBE7B",
18 cyan = "#008080",
19 darkblue = "#081633",
20 green = "#98be65",
21 orange = "#FF8800",
22 violet = "#a9a1e1",
23 magenta = "#c678dd",
24 blue = "#51afef",
25 red = "#ec5f67",
26 }
27 local mode_color = {
28 n = colors.red,
29 i = colors.green,
30 v = colors.blue,
31 [""] = colors.blue,
32 V = colors.blue,
33 c = colors.magenta,
34 no = colors.red,
35 s = colors.orange,
36 S = colors.orange,
37 [" "] = colors.orange,
38 ic = colors.yellow,
39 R = colors.violet,
40 Rv = colors.violet,
41 cv = colors.red,
42 ce = colors.red,
43 r = colors.cyan,
44 rm = colors.cyan,
45 ["r?"] = colors.cyan,
46 ["!"] = colors.red,
47 t = colors.red,
48 }
49
50 local conditions = {
51 buffer_not_empty = function()
52 return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
53 end,
54 hide_in_width = function()
55 return vim.fn.winwidth(0) > 80
56 end,
57 check_git_workspace = function()
58 local filepath = vim.fn.expand("%:p:h")
59 local gitdir = vim.fn.finddir(".git", filepath .. ";")
60 return gitdir and #gitdir > 0 and #gitdir < #filepath
61 end,
62 }
63
64 local config = {
65 options = {
66 icons_enabled = true,
67 component_separators = "",
68 section_separators = "",
69 theme = "auto",
70 },
71 sections = {
72 -- these are to remove the defaults
73 lualine_a = {},
74 lualine_b = {},
75 lualine_y = {},
76 lualine_z = {},
77 -- These will be filled later
78 lualine_c = {},
79 lualine_x = {},
80 },
81 inactive_sections = {
82 -- these are to remove the defaults
83 lualine_a = {},
84 lualine_b = {},
85 lualine_y = {},
86 lualine_z = {},
87 lualine_c = {},
88 lualine_x = {},
89 },
90 }
91
92 -- Inserts a component in lualine_c at left section
93 local function ins_left(component)
94 table.insert(config.sections.lualine_c, component)
95 end
96
97 -- Inserts a component in lualine_x at right section
98 local function ins_right(component)
99 table.insert(config.sections.lualine_x, component)
100 end
101
102 local trouble = require("trouble")
103
104 ins_left({
105 function()
106 return "▊"
107 end,
108 color = function()
109 return {
110 fg = mode_color[vim.fn.mode()],
111 } -- Sets highlighting of component
112 end,
113 padding = {
114 left = 0,
115 right = 1,
116 }, -- We don't need space before this
117 })
118
119 ins_left({
120 -- mode component
121 function()
122 local mode = {
123 n = "Normal",
124 v = "Visual",
125 o = "Operator-pending",
126 i = "Insert",
127 c = "Cmd-line",
128 s = "Select",
129 x = "Visual",
130 t = "Terminal-Job",
131 ["!"] = "Insert and Cmd-line",
132 }
133 return "⚡" .. mode[vim.fn.mode()]
134 end,
135 color = function()
136 -- auto change color according to neovims mode
137 return {
138 fg = mode_color[vim.fn.mode()],
139 }
140 end,
141 padding = {
142 right = 0,
143 },
144 })
145
146 ins_left({
147 "branch",
148 icon = "",
149 color = {
150 fg = colors.violet,
151 gui = "bold",
152 },
153 })
154
155 ins_left({
156 "filesize",
157 cond = conditions.buffer_not_empty,
158 color = {
159 fg = colors.violet,
160 gui = "bold",
161 },
162 })
163
164 ins_left({
165 "location",
166 color = {
167 fg = colors.violet,
168 gui = "bold",
169 },
170 })
171
172 ins_left({
173 "diagnostics",
174 sources = { "nvim_diagnostic" },
175 symbols = {
176 error = LazyVim.config.icons.diagnostics.Error,
177 warn = LazyVim.config.icons.diagnostics.Warn,
178 info = LazyVim.config.icons.diagnostics.Info,
179 },
180 diagnostics_color = {
181 color_error = {
182 fg = colors.red,
183 },
184 color_warn = {
185 fg = colors.yellow,
186 },
187 color_info = {
188 fg = colors.cyan,
189 },
190 },
191 color = {
192 fg = colors.fg,
193 gui = "bold",
194 },
195 })
196
197 ins_left({
198 function()
199 return " " .. require("dap").status()
200 end,
201 cond = function()
202 return package.loaded["dap"] and require("dap").status() ~= ""
203 end,
204 color = {
205 fg = colors.fg,
206 gui = "bold",
207 },
208 })
209
210 ins_left({
211 "filename",
212 cond = conditions.buffer_not_empty,
213 color = {
214 fg = colors.magenta,
215 gui = "bold",
216 },
217 })
218
219 local symbols = trouble.statusline({
220 mode = "lsp_document_symbols",
221 groups = {},
222 title = false,
223 filter = { range = true },
224 format = "{kind_icon}{symbol.name:Normal}",
225 hl_group = "lualine_c_normal",
226 })
227 --
228 ins_left({
229 symbols.get,
230 cond = symbols.has,
231 })
232 -- -- Insert mid section. You can make any number of sections in neovim :)
233 -- -- for lualine it's any number greater then 2
234 ins_left({
235 function()
236 return "%="
237 end,
238 })
239
240 -- Add components to right sections
241
242 ins_right({
243 "searchcount",
244 color = {
245 fg = colors.yellow,
246 },
247 })
248
249 ins_right({
250 "selectioncount",
251 })
252
253 ins_right({
254 "fzf",
255 })
256
257 -- ins_right({
258 -- "windows",
259 -- })
260
261 -- ins_right({
262 -- "tabs",
263 -- })
264
265 ins_right({
266 "progress",
267 color = {
268 gui = "bold",
269 },
270 })
271
272 ins_right({
273 "diff",
274 -- Is it me or the symbol for modified us really weird
275 symbols = {
276 added = " ",
277 modified = " ",
278 removed = " ",
279 },
280 diff_color = {
281 added = {
282 fg = colors.green,
283 },
284 modified = {
285 fg = colors.orange,
286 },
287 removed = {
288 fg = colors.red,
289 },
290 },
291 cond = conditions.hide_in_width,
292 })
293
294 ins_right({
295 -- Lsp server name .
296 function()
297 local msg = "No Active Lsp"
298 local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
299 local clients = vim.lsp.get_clients()
300 if next(clients) == nil then
301 return ""
302 end
303 for _, client in ipairs(clients) do
304 local filetypes = client.config.filetypes
305 if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
306 return client.name
307 end
308 end
309 return msg
310 end,
311 color = {
312 gui = "bold",
313 },
314 })
315
316 local memory_read_timer = (vim.uv or vim.loop).new_timer()
317 local free_useage
318
319 local memory_useage = ""
320 if memory_read_timer then
321 memory_read_timer:start(
322 1000,
323 3000,
324 vim.schedule_wrap(function()
325 free_useage = vim.uv.get_available_memory() / vim.uv.get_total_memory()
326 memory_useage = string.format(" %.1f%%%%", 100 * (1 - free_useage))
327 end)
328 )
329 end
330
331 ins_right({
332 function()
333 return memory_useage
334 end,
335 color = function()
336 local fg = ""
337 local value = 100 * (free_useage or 0)
338 if value >= 85 then
339 fg = colors.green
340 elseif value >= 70 then
341 fg = colors.blue
342 elseif value >= 65 then
343 fg = colors.yellow
344 elseif value >= 40 then
345 fg = colors.orange
346 elseif value >= 30 then
347 fg = colors.red
348 end
349
350 return {
351 fg = fg,
352 }
353 end,
354 })
355
356 ins_right(LazyVim.lualine.cmp_source("codeium"))
357
358
359
360 ins_right({
361 "o:encoding", -- option component same as &encoding in viml
362 fmt = string.upper, -- I'm not sure why it's upper case either ;)
363 cond = conditions.hide_in_width,
364 color = {
365 fg = colors.green,
366 gui = "bold",
367 },
368 })
369
370 ins_right({
371 function()
372 return " " .. os.date("%R")
373 end,
374 color = function()
375 return {
376 fg = mode_color[vim.fn.mode()],
377 gui = "bold",
378 }
379 end,
380 })
381
382 ins_right({
383 "fileformat",
384 fmt = string.upper,
385 icons_enabled = true, -- I think icons are cool but Eviline doesn't have them. sigh
386 color = function()
387 return {
388 fg = mode_color[vim.fn.mode()],
389 gui = "bold",
390 }
391 end,
392 })
393
394 ins_right({
395 function()
396 return "▊"
397 end,
398 color = function()
399 return {
400 fg = mode_color[vim.fn.mode()],
401 } -- Sets highlighting of component
402 end,
403 padding = {
404 left = 1,
405 },
406 })
407
408 return config
409 end,
410 enable = true,
411}