dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

commit c0aa1e7e8a5cc5e801a8de3721e42ad38e8d4c49
parent 674fb6a22ce23bca72515f6d46552cc57b7cb9ce
Author: tongong <tongong@gmx.net>
Date:   Sun, 31 Oct 2021 18:58:22 +0100

[nvim] new custom statusline

Diffstat:
Mconfig/nvim/colors/dim.vim | 44+-------------------------------------------
Mconfig/nvim/init.vim | 8++++----
Aconfig/nvim/lua/statusline.lua | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mconfig/nvim/restore-view.vim | 2+-
4 files changed, 78 insertions(+), 48 deletions(-)

diff --git a/config/nvim/colors/dim.vim b/config/nvim/colors/dim.vim @@ -99,49 +99,6 @@ highlight MatchParen cterm=none ctermbg=5 ctermfg=0 highlight clear SignColumn highlight ColorColumn ctermfg=0 ctermbg=3 -"### LIGHTLINE ######################################################### -" this is a modified version of the 16color colorscheme to fit my needs -let s:black = [ '#000000', 0 ] -let s:maroon = [ '#800000', 1 ] -let s:green = [ '#008000', 2 ] -let s:olive = [ '#808000', 3 ] -let s:navy = [ '#000080', 4 ] -let s:purple = [ '#800080', 5 ] -let s:teal = [ '#008080', 6 ] -let s:silver = [ '#c0c0c0', 7 ] -let s:gray = [ '#808080', 8] -let s:red = [ '#ff0000', 9 ] -let s:lime = [ '#00ff00', 10 ] -let s:yellow = [ '#ffff00', 11 ] -let s:blue = [ '#0000ff', 12 ] -let s:fuchsia = [ '#ff00ff', 13 ] -let s:aqua = [ '#00ffff', 14 ] -let s:white = [ '#ffffff', 15 ] - -let s:black = s:gray - -let s:p = {'normal': {}, 'inactive': {}, 'insert': {}, 'replace': {}, 'visual': {}, 'tabline': {}} -let s:p.normal.left = [ [ s:white, s:blue ], [ s:white, s:gray ] ] -let s:p.normal.middle = [ [ s:silver, s:black ] ] -let s:p.normal.right = [ [ s:white, s:blue ], [ s:white, s:gray ] ] -let s:p.normal.error = [ [ s:black, s:red ] ] -let s:p.normal.warning = [ [ s:black, s:yellow ] ] -let s:p.inactive.left = [ [ s:silver, s:gray ], [ s:gray, s:black ] ] -let s:p.inactive.middle = [ [ s:silver, s:black ] ] -let s:p.inactive.right = [ [ s:silver, s:gray ], [ s:gray, s:black ] ] -let s:p.insert.left = [ [ s:white, s:green ], [ s:white, s:gray ] ] -let s:p.insert.right = copy(s:p.insert.left) -let s:p.replace.left = [ [ s:white, s:red ], [ s:white, s:gray ] ] -let s:p.replace.right = copy(s:p.replace.left) -let s:p.visual.left = [ [ s:white, s:purple ], [ s:white, s:gray ] ] -let s:p.visual.right = copy(s:p.visual.left) -let s:p.tabline.left = [ [ s:silver, s:black ] ] -let s:p.tabline.tabsel = copy(s:p.normal.right) -let s:p.tabline.middle = [ [ s:silver, s:black ] ] -let s:p.tabline.right = copy(s:p.normal.right) - -let g:lightline#colorscheme#dim#palette = lightline#colorscheme#flatten(s:p) - "### MARKDOWN SYNTAX ################################################### " gruvbox markdown theme with standard terminal colors highlight markdownH1 ctermfg=2 cterm=bold @@ -177,3 +134,4 @@ highligh SpellLocal ctermfg=0 ctermbg=1 " make other errors less eye-hurting highlight clear Error highlight Error ctermfg=0 ctermbg=1 +highlight Todo ctermfg=0 ctermbg=3 diff --git a/config/nvim/init.vim b/config/nvim/init.vim @@ -16,7 +16,7 @@ set foldlevelstart=20 set number call matchadd('ColorColumn', '\%80v.', 100) " color column set signcolumn=yes -set noshowmode " not needed because of lightline statusline +set noshowmode " not needed because of statusline set fillchars=eob:\ , set shortmess+=I " necessary to color the active line number @@ -55,7 +55,6 @@ Plug 'ap/vim-css-color' Plug 'axvr/zepl.vim' Plug 'embear/vim-localvimrc' Plug 'godlygeek/tabular' -Plug 'itchyny/lightline.vim' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' Plug 'junegunn/goyo.vim' @@ -69,8 +68,9 @@ call plug#end() "### SETTINGS ############################################################## colorscheme dim -" statusbar -let g:lightline = { 'colorscheme': 'dim', } +" statusline +" TODO add git diff to statusline +lua require("statusline") " spell check toggle let g:myLangList = ["nospell", "de_de", "en_us"] diff --git a/config/nvim/lua/statusline.lua b/config/nvim/lua/statusline.lua @@ -0,0 +1,72 @@ +-- inspired by: https://nihilistkitten.me/nvim-lua-statusline/ +-- https://elianiva.my.id/post/neovim-lua-statusline +-- lightline + +-- colorscheme +local c_highlight = 3 -- yellow +local c_grey_light = 8 +local c_grey_dark = 237 +local c_white = 15 + +local function highlight(group, fg, bg) + vim.cmd("highlight " .. group .. " ctermfg=" .. fg .. " ctermbg=" .. bg) +end +function status_line_highlights() + vim.cmd("highlight StatusLine cterm=None ctermfg=15 ctermbg=None") + highlight("StatusHighlight", c_grey_dark, c_highlight) + highlight("StatusLight", c_white, c_grey_light) + highlight("StatusDark", c_highlight, c_grey_dark) + highlight("StatusNone", "None", "None") +end + +local function get_mode() + local modes = { + [ 'n'] = 'NORMAL', [ 'no'] = 'N-PENDING', [ 'v'] = 'VISUAL', + [ 'V'] = 'V-LINE', [ ''] = 'V-BLOCK', [ 's'] = 'SELECT', + [ 'S'] = 'S-LINE', [ ''] = 'S-BLOCK', [ 'i'] = 'INSERT', + [ 'ic'] = 'INSERT', [ 'R'] = 'REPLACE', [ 'Rv'] = 'V-REPLACE', + [ 'c'] = 'COMMAND', [ 'cv'] = 'VIM-EX ', [ 'ce'] = 'EX', + [ 'r'] = 'PROMT', [ 'rm'] = 'MORE', [ 'r?'] = 'CONFIRM', + [ '!'] = 'SHELL', [ 't'] = 'TERMINAL', + } + local mode = vim.api.nvim_get_mode() + if mode == nil then + return "?" + else + return modes[mode.mode] + end +end + +function status_line(active) + local active_highlight = "%#StatusHighlight#" + if active == 0 then + active_highlight = "%#StatusDark#" + end + return table.concat { + active_highlight, + " ", get_mode(), " ", + "%#StatusLight#", + " %f ", + "%#StatusNone#", + "%=", + "%#StatusLight#", + " %p%% ", + active_highlight, + " %l:%c " + } +end + +status_line_highlights() +vim.o.statusline = "%!v:lua.status_line(0)" + +vim.api.nvim_exec([[ + augroup Statusline + au! + au WinEnter,BufEnter * setlocal statusline=%!v:lua.status_line(1) + au WinLeave,BufLeave * setlocal statusline=%!v:lua.status_line(0) + + au FocusGained * setlocal statusline=%!v:lua.status_line(1) + au FocusLost * setlocal statusline=%!v:lua.status_line(0) + au User GoyoLeave nested lua status_line_highlights() + augroup END +]], false) diff --git a/config/nvim/restore-view.vim b/config/nvim/restore-view.vim @@ -61,5 +61,5 @@ augroup AutoView " the loadview could change foldmethod. in this case foldmethod is " correctly reset using filetype rules " for the lightline part see https://github.com/itchyny/lightline.vim/issues/484 - autocmd BufWinEnter ?* if MakeViewCheck() | silent! loadview | let &l:filetype = &l:filetype | call lightline#update() | endif + autocmd BufWinEnter ?* if MakeViewCheck() | silent! loadview | let &l:filetype = &l:filetype | endif augroup END