all repos — dotfiles @ 6173b0387d9272dc6064d76bca5a1373f3eedf86

my *nix dotfiles

nvim: Rewrite statusline in lua
Anirudh Oppiliappan x@icyphox.sh
Sat, 30 Jan 2021 20:04:54 +0530
commit

6173b0387d9272dc6064d76bca5a1373f3eedf86

parent

305753e33f546d46cdbe2ff65458100410feafcd

3 files changed, 53 insertions(+), 38 deletions(-)

jump to
M config/nvim/init.luaconfig/nvim/init.lua

@@ -17,3 +17,4 @@ paq 'zah/nim.vim'

require('settings') require('maps') +require('statusline')
A config/nvim/lua/statusline.lua

@@ -0,0 +1,52 @@

+local mode_map = { + ['n'] = 'normal ', + ['no'] = 'n·operator pending ', + ['v'] = 'visual ', + ['V'] = 'v·line ', + [''] = 'v·block ', + ['s'] = 'select ', + ['S'] = 's·line ', + [''] = 's·block ', + ['i'] = 'insert ', + ['R'] = 'replace ', + ['Rv'] = 'v·replace ', + ['c'] = 'command ', + ['cv'] = 'vim ex ', + ['ce'] = 'ex ', + ['r'] = 'prompt ', + ['rm'] = 'more ', + ['r?'] = 'confirm ', + ['!'] = 'shell ', + ['t'] = 'terminal ' +} + +local function mode() + local m = vim.api.nvim_get_mode().mode + if mode_map[m] == nil then return m end + return mode_map[m] +end + +-- set highlights for statusline sections +vim.api.nvim_exec( +[[ + hi PrimaryBlock ctermfg=06 ctermbg=00 + hi SecondaryBlock ctermfg=08 ctermbg=00 + hi Blanks ctermfg=07 ctermbg=00 +]], false) + + +local stl = { + '%#PrimaryBlock#', + mode(), + '%#SecondaryBlock#', + '%#Blanks#', + '%f', + '%m', + '%=', + '%#SecondaryBlock#', + '%l,%c ', + '%#PrimaryBlock#', + '%{&filetype}', +} + +vim.o.statusline = table.concat(stl)
D config/nvim/plugin/statusline.vim

@@ -1,38 +0,0 @@

-" statusline -let g:currentmode={ - \ 'n' : 'normal ', - \ 'no' : 'n·operator pending ', - \ 'v' : 'visual ', - \ 'V' : 'v·line ', - \ '' : 'v·block ', - \ 's' : 'select ', - \ 'S' : 's·line ', - \ '' : 's·block ', - \ 'i' : 'insert ', - \ 'R' : 'replace ', - \ 'Rv' : 'v·replace ', - \ 'c' : 'command ', - \ 'cv' : 'vim ex ', - \ 'ce' : 'ex ', - \ 'r' : 'prompt ', - \ 'rm' : 'more ', - \ 'r?' : 'confirm ', - \ '!' : 'shell ', - \ 't' : 'terminal '} - -hi PrimaryBlock ctermfg=06 ctermbg=00 -hi SecondaryBlock ctermfg=08 ctermbg=00 -hi Blanks ctermfg=07 ctermbg=00 - -set statusline= -set statusline+=%#PrimaryBlock# -set statusline+=\ %{g:currentmode[mode()]} -set statusline+=%#SecondaryBlock# -set statusline+=%#Blanks# -set statusline+=\ %f\ -set statusline+=%m -set statusline+=%= -set statusline+=%#SecondaryBlock# -set statusline+=\ %l,%c\ -set statusline+=%#PrimaryBlock# -set statusline+=%{&filetype}