From a4cbc15d0caa17865d3a855df371a797b1d97b85 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sun, 13 Feb 2022 21:17:42 +0100 Subject: [PATCH] vim: make mode in statusline always same width --- config/nvim/lua/fs/config/lualine.lua | 63 ++++++++++++++++++++------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/config/nvim/lua/fs/config/lualine.lua b/config/nvim/lua/fs/config/lualine.lua index c941f57..6072e1a 100644 --- a/config/nvim/lua/fs/config/lualine.lua +++ b/config/nvim/lua/fs/config/lualine.lua @@ -48,6 +48,44 @@ local theme = (function() } end)() +local MODE_MAP = { + ['n'] = 'Normal ', + ['no'] = 'O-Pend ', + ['nov'] = 'O-Pend ', + ['noV'] = 'O-Pend ', + ['no'] = 'O-Pend ', + ['niI'] = 'Normal ', + ['niR'] = 'Normal ', + ['niV'] = 'Normal ', + ['nt'] = 'Normal ', + ['v'] = 'Visual ', + ['vs'] = 'Visual ', + ['V'] = 'V-Line ', + ['Vs'] = 'V-Line ', + [''] = 'V-Block', + ['s'] = 'V-Block', + ['s'] = 'Select ', + ['S'] = 'S-Line ', + [''] = 'S-Block', + ['i'] = 'Insert ', + ['ic'] = 'Insert ', + ['ix'] = 'Insert ', + ['R'] = 'Replace', + ['Rc'] = 'Replace', + ['Rx'] = 'Replace', + ['Rv'] = 'V-Repl ', + ['Rvc'] = 'V-Repl ', + ['Rvx'] = 'V-Repl ', + ['c'] = 'Command', + ['cv'] = ' Ex ', + ['ce'] = ' Ex ', + ['r'] = 'Replace', + ['rm'] = ' More ', + ['r?'] = 'Confirm', + ['!'] = ' Shell ', + ['t'] = ' Term ', +} + local update_status = function(self, is_focused) self.options.colored = is_focused return self.super.update_status(self, is_focused) @@ -59,14 +97,13 @@ diff.update_status = update_status local filetype = require'lualine.components.filetype':extend() filetype.update_status = update_status -local path = function() - return vim.fn.pathshorten(vim.fn.fnamemodify(vim.fn.expand('%'), ':p')) -end - local parts = { split = function() return '%=' end, - mode = 'mode', + mode = function() + local code = vim.api.nvim_get_mode().mode + return MODE_MAP[code] or code + end, paste = { function() return '' end, @@ -76,12 +113,9 @@ local parts = { end }, - branch = { - 'branch', - icon = '', - }, + branch = { 'branch', icon = '' }, - diff= { + diff = { diff, diff_color = { added = { fg = colors.green }, @@ -91,14 +125,13 @@ local parts = { padding = 0, }, - path = path, + path = function() + return vim.fn.pathshorten(vim.fn.fnamemodify(vim.fn.expand('%'), ':p')) + end, filetype = filetype, - fileformat = { - 'fileformat', - padding = { left = 0, right = 1 }, - }, + fileformat = { 'fileformat', padding = { left = 0, right = 1 } }, progress = { function()