Closed aniketgm closed 2 years ago
Once you've a mode map there's really not much you need to have your own mode component that's why lualine doesn't have a separate option for mode map .
For example you can just use a function like this for your mode
local mode_map = {
['n'] = 'NORMAL',
['no'] = 'O-PENDING',
['nov'] = 'O-PENDING',
['noV'] = 'O-PENDING',
['no'] = 'O-PENDING',
['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-REPLACE',
['Rvc'] = 'V-REPLACE',
['Rvx'] = 'V-REPLACE',
['c'] = 'COMMAND',
['cv'] = 'EX',
['ce'] = 'EX',
['r'] = 'REPLACE',
['rm'] = 'MORE',
['r?'] = 'CONFIRM',
['!'] = 'SHELL',
['t'] = 'TERMINAL',
}
require('lualine').setup({
sections = {
lualine_a = {function ()
return mode_map[vim.api.nvim_get_mode().mode] or "__"
end},
}
})
Though if I understand correctly all you want is for lualine to show just first character of mode . There's a easier way to do that . In lualine you can apply fmt
option to any component. In the fmt option you can manipulate the components result as you like . For example you can show just first character of mode just with this.
require('lualine').setup({
sections = {
lualine_a = { {'mode', fmt = function(res) return res:sub(1,1) end} },
}
})
fmt = function(res) return res:sub(1,1) end
Is this a lualine feature or a lua feature altogether ? coz this is really cool. Cool in the sense, for as simple as shortening a mode name, a small function did the whole trick instead of defining the whole mode_map, which I was doing earlier. Thanks. P.S. I don't know lua. I'm still learning.
Is this a lualine feature or a lua feature altogether ?
Using fmt
to manipulate component results in lualine feature the string substring function used in this case is part of lua standered library.
P.S. I don't know lua. I'm still learning
You should take a look at nvim-lua-guide if you haven't already it's a great place to get started with lua in neovim . Also lua x in y minutes page is nice to familiarize with the syntax.
I believe this issue is resolved.
I use this
local mode_map = {
['NORMAL'] = 'N',
['O-PENDING'] = 'N?',
['INSERT'] = 'I',
['VISUAL'] = 'V',
['V-BLOCK'] = 'VB',
['V-LINE'] = 'VL',
['V-REPLACE'] = 'VR',
['REPLACE'] = 'R',
['COMMAND'] = '!',
['SHELL'] = 'SH',
['TERMINAL'] = 'T',
['EX'] = 'X',
['S-BLOCK'] = 'SB',
['S-LINE'] = 'SL',
['SELECT'] = 'S',
['CONFIRM'] = 'Y?',
['MORE'] = 'M',
}
require('lualine').setup({
sections = {
lualine_a = { {'mode', fmt = function(s) return mode_map[s] or s end} },
}
})
Question: Is there a way to create a mode map for the modes ?
Description: I am using vim-airline and thought to give lualine a try. So, in vim-airline, there is a feature to set a map for different modes like this:
This helps me keep things simple in status bar. I checked the lualine help couldn't find any. Is there something similar available in lualine that I'm not aware ? This is how it looks with the![dummy2](https://user-images.githubusercontent.com/14215698/158973527-f45c36aa-3585-4094-9bb8-68e76993c35c.png)
vim-airline mode_map
: