diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-09-05 05:43:27 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-09-05 05:43:27 +0200 |
| commit | ea2ea8dfa5718766865feaecda8162cec40e6ca3 (patch) | |
| tree | 8599ffb7efcf8c840561eaeb71938cdc84b820c2 /linux/home/.vim/autoload | |
| parent | 68f64c067979cf24e5dbaeaa20e7b7cf53252f97 (diff) | |
| download | dotfiles-ea2ea8dfa5718766865feaecda8162cec40e6ca3.tar.gz dotfiles-ea2ea8dfa5718766865feaecda8162cec40e6ca3.zip | |
New vim config
Diffstat (limited to 'linux/home/.vim/autoload')
| -rw-r--r-- | linux/home/.vim/autoload/autoload/statusline.vim | 267 | ||||
| -rw-r--r-- | linux/home/.vim/autoload/statusline.vim | 312 |
2 files changed, 443 insertions, 136 deletions
diff --git a/linux/home/.vim/autoload/autoload/statusline.vim b/linux/home/.vim/autoload/autoload/statusline.vim new file mode 100644 index 0000000..bf5f972 --- /dev/null +++ b/linux/home/.vim/autoload/autoload/statusline.vim @@ -0,0 +1,267 @@ +" statusline.vim + +if exists('g:loaded_statusline') | finish | endif +let g:loaded_statusline = 1 + +" --- Detect Nerd Fonts --- +function! s:HasNerdFonts() + if exists('g:statusline_nerd_fonts') + return g:statusline_nerd_fonts + endif + + if executable('fc-list') + let l:output = system('fc-list | grep -i nerd') + if len(split(l:output, '\n')) > 0 + return 1 + endif + endif + + return 0 +endfunction + +let g:statusline_has_nerd_fonts = s:HasNerdFonts() + +" --- Color Palette --- +let g:StslineColorGreen = '#2BBB4F' +let g:StslineColorBlue = '#4799EB' +let g:StslineColorViolet = '#986FEC' +let g:StslineColorYellow = '#D7A542' +let g:StslineColorOrange = '#EB754D' +let g:StslineColorLight = '#C0C0C0' +let g:StslineColorDark = '#080808' +let g:StslineColorDark1 = '#181818' +let g:StslineColorDark2 = 'NONE' +let g:StslineColorDark3 = '#303030' + +let g:StslineBackColor = g:StslineColorDark2 +let g:StslineOnBackColor = g:StslineColorLight +let g:StslinePriColor = g:StslineColorGreen +let g:StslineOnPriColor = g:StslineColorDark +let g:StslineSecColor = g:StslineColorDark3 +let g:StslineOnSecColor = g:StslineColorLight + +" --- Highlight Groups --- +" Initial setup of highlight groups (will be updated by UpdateStslineColors) +execute 'highlight StslinePriColorBG guifg=' . g:StslineOnPriColor . ' guibg=' . g:StslinePriColor +execute 'highlight StslineSecColorFG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor +execute 'highlight StslineSecColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineSecColor +execute 'highlight StslineBackColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineBackColor +execute 'highlight StslineBackColorFGSecColorBG guifg=' . g:StslineBackColor . ' guibg=' . g:StslineSecColor +execute 'highlight StslineSecColorFGBackColorBG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor +execute 'highlight StslineModColorFG guifg=' . g:StslineColorYellow . ' guibg=' . g:StslineBackColor +execute 'highlight StslinePriColorBG_SecColorBG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor +execute 'highlight StslineModeSep guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor +execute 'highlight StslineGitSep guifg=' . g:StslineSecColor . ' guibg=' . g:StslineColorDark2 + +" --- Statusline Settings --- +if has('nvim') + set laststatus=3 +else + set laststatus=2 +endif + +"set noshowmode +"set termguicolors + +let space = '' + +" Get Statusline mode & also set primary color for that mode +function! autoload#statusline#StslineMode() abort + let l:CurrentMode = mode() + + if l:CurrentMode ==# 'n' + let g:StslinePriColor = g:StslineColorGreen + let b:CurrentMode = 'NORMAL ' + elseif l:CurrentMode ==# 'i' + let g:StslinePriColor = g:StslineColorViolet + let b:CurrentMode = 'INSERT ' + elseif l:CurrentMode ==# 'c' + let g:StslinePriColor = g:StslineColorYellow + let b:CurrentMode = 'COMMAND' + elseif l:CurrentMode ==# 'v' + let g:StslinePriColor = g:StslineColorBlue + let b:CurrentMode = 'VISUAL ' + elseif l:CurrentMode ==# '\<C-v>' + let g:StslinePriColor = g:StslineColorBlue + let b:CurrentMode = 'V-BLOCK' + elseif l:CurrentMode ==# 'V' + let g:StslinePriColor = g:StslineColorBlue + let b:CurrentMode = 'V-LINE ' + elseif l:CurrentMode ==# 'R' + let g:StslinePriColor = g:StslineColorViolet + let b:CurrentMode = 'REPLACE' + elseif l:CurrentMode ==# 's' + let g:StslinePriColor = g:StslineColorBlue + let b:CurrentMode = 'SELECT ' + elseif l:CurrentMode ==# 't' + let g:StslinePriColor = g:StslineColorYellow + let b:CurrentMode = 'TERM ' + elseif l:CurrentMode ==# '!' + let g:StslinePriColor = g:StslineColorYellow + let b:CurrentMode = 'SHELL ' + else + let g:StslinePriColor = g:StslineColorGreen + endif + + call autoload#statusline#UpdateStslineColors() + + return b:CurrentMode +endfunction + +function! autoload#statusline#UpdateStslineColors() abort + execute 'highlight StslinePriColorBG guifg=' . g:StslineOnPriColor . ' guibg=' . g:StslinePriColor + execute 'highlight StslinePriColorBGBold guifg=' . g:StslineOnPriColor . ' guibg=' . g:StslinePriColor . ' gui=bold' + execute 'highlight StslinePriColorFG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineBackColor + execute 'highlight StslinePriColorFGSecColorBG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor + execute 'highlight StslineModeSep guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor + execute 'highlight StslineGitSep guifg=' . g:StslineSecColor . ' guibg=' . g:StslineColorDark2 + execute 'highlight StslineSecColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineSecColor + execute 'highlight StslineBackColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineBackColor + execute 'highlight StslineBackColorFGSecColorBG guifg=' . g:StslineBackColor . ' guibg=' . g:StslineSecColor + execute 'highlight StslineSecColorFGBackColorBG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor + execute 'highlight StslineModColorFG guifg=' . g:StslineColorYellow . ' guibg=' . g:StslineBackColor + execute 'highlight StslinePriColorBG_SecColorBG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor + execute 'highlight StslineSecColorFG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor +endfunction + +function! autoload#statusline#GetGitBranch() abort + let b:GitBranch = '' + try + let l:dir = expand('%:p:h') + let l:gitrevparse = system("git -C ".l:dir." rev-parse --abbrev-ref HEAD") + if !v:shell_error + let icon = g:statusline_has_nerd_fonts ? ' ' : ' [git] ' + let b:GitBranch = icon . substitute(l:gitrevparse, '\n', '', 'g') . ' ' + endif + catch + endtry +endfunction + +function! autoload#statusline#GetFileType() abort + if !g:statusline_has_nerd_fonts + let b:FiletypeIcon = '' + return + endif + if &filetype ==# 'typescript' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'html' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'scss' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'css' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'javascript' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'javascriptreact' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'markdown' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'sh' || &filetype ==# 'zsh' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'vim' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'rust' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'ruby' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'cpp' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'c' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'go' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'lua' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'haskell' | let b:FiletypeIcon = ' ' + else | let b:FiletypeIcon = ' ' + endif +endfunction + +function! autoload#statusline#ActivateStatusline() abort + call autoload#statusline#GetFileType() + call autoload#statusline#GetGitBranch() " Ensure git branch is updated + + let current_mode_str = autoload#statusline#StslineMode() + call autoload#statusline#UpdateStslineColors() + + let readonly_icon = g:statusline_has_nerd_fonts ? ' ' : '[RO] ' + let modified_icon = g:statusline_has_nerd_fonts ? ' ' : '[+] ' + let git_sep = g:statusline_has_nerd_fonts ? '' : ' ' + let file_sep1 = g:statusline_has_nerd_fonts ? ' ' : ' ' + let file_sep2 = g:statusline_has_nerd_fonts ? '' : '' + + " Get dynamic parts as simple strings + let git_status_str = get(b:, "coc_git_status", get(b:, "GitBranch", "")) + let git_blame_str = get(b:, "coc_git_blame", "") + let filetype_icon_str = get(b:, "FiletypeIcon", "") + let file_encoding_str = '' + if &fenc != "utf-8" + let file_encoding_str = &fenc . ' ' + endif + + " Build the statusline as a static string + let l:statusline = '' + + let l:statusline .= '%#StslinePriColorBG# ' . current_mode_str . '' + let l:statusline .= '%#StslineModeSep#' . git_sep + let l:statusline .= '%#StslineSecColorBG#' . git_status_str . git_blame_str + let l:statusline .= '%#StslineGitSep#' . git_sep + + " File info (Readonly, Modified, Filename) + let l:statusline .= '%#StslinePriColorFG#' + if &readonly + let l:statusline .= readonly_icon + endif + let l:statusline .= ' %F ' + if &modified + let l:statusline .= modified_icon + endif + + " Right align everything after this + let l:statusline .= '%=' + + " Right side (Filetype, Encoding, Position) + let l:statusline .= '%#StslinePriColorFG# ' . filetype_icon_str . '%y' + let l:statusline .= '%#StslineSecColorFG#' . file_sep1 + "let l:statusline .= '%#StslineSecColorBG# ' . file_encoding_str + let l:statusline .= '%#StslinePriColorFGSecColorBG#' . file_sep2 + let l:statusline .= '%#StslinePriColorBG# %p%% %#StslinePriColorBGBold#%l%#StslinePriColorBG#/%L :%c ' + let l:statusline .= '%#StslineBackColorBG#' + + " Set the statusline for the current buffer + let &l:statusline = l:statusline +endfunction + +function! autoload#statusline#DeactivateStatusline() abort + let git_sep = g:statusline_has_nerd_fonts ? '' : '' + let readonly_icon = g:statusline_has_nerd_fonts ? ' ' : '[RO] ' + let modified_icon = g:statusline_has_nerd_fonts ? ' ' : '[+] ' + + " NOTE: This DeactivateStatusline function still uses %{} for dynamic parts. + " If you encounter general E518 or other issues related to %{} expressions, + " you will need to refactor this function to build a static string + " similar to how ActivateStatusline now does it. + if !exists("b:GitBranch") || b:GitBranch == '' + let statusline = + \ '%#StslineSecColorBG# INACTIVE ' . + \ '%{get(b:,"coc_git_statusline",b:GitBranch)}%{get(b:,"coc_git_blame","")}' . + \ '%#StslineBackColorFGSecColorBG#' . git_sep . + \ '%#StslineBackColorBG# %{&readonly?"' . readonly_icon . '":""}%F ' . + \ '%#StslineModColorFG#%{&modified?"' . modified_icon . '":""}' . + \ '%=%#StslineBackColorBG# %{b:FiletypeIcon}%{&filetype}' . + \ '%#StslineSecColorFGBackColorBG# | %p%% %l/%L :%c' + else + let statusline = + \ '%#StslineSecColorBG# %{get(b:,"coc_git_statusline",b:GitBranch)}%{get(b:,"coc_git_blame","")}' . + \ '%#StslineBackColorFGSecColorBG#' . git_sep . + \ '%#StslineBackColorBG# %{&readonly?"' . readonly_icon . '":""}%F ' . + \ '%#StslineModColorFG#%{&modified?"' . modified_icon . '":""}' . + \ '%=%#StslineBackColorBG# %{b:FiletypeIcon}%{&filetype}' . + \ '%#StslineSecColorFGBackColorBG# | %p%% %l/%L :%c' + endif + + execute 'setlocal statusline=' . substitute(statusline, '"', '\\"', 'g') +endfunction + +augroup StatuslineGit + autocmd! + autocmd BufEnter * call autoload#statusline#GetGitBranch() +augroup END + +augroup SetStsline + autocmd! + autocmd BufEnter,WinEnter * call autoload#statusline#ActivateStatusline() + autocmd ModeChanged * call autoload#statusline#ActivateStatusline() +augroup END + +augroup StatuslineAutoReload + autocmd! + autocmd BufWritePost statusline.vim source <afile> | call autoload#statusline#ActivateStatusline() +augroup END + +"call autoload#statusline#ActivateStatusline() diff --git a/linux/home/.vim/autoload/statusline.vim b/linux/home/.vim/autoload/statusline.vim index 5e5a671..bf5f972 100644 --- a/linux/home/.vim/autoload/statusline.vim +++ b/linux/home/.vim/autoload/statusline.vim @@ -1,105 +1,69 @@ -"" This was made by Reddit user u/SamLovesNotion. Also with the help of - https://tdaly.co.uk/projects/vim-statusline-generator/ for learning the syntax. Sorry for English & grammar, this post was made in hurry. - -" Images - https://www.reddit.com/r/vim/comments/ld8h2j/i_made_a_status_line_from_scratch_no_plugins_used/ -" I have used Nerd icon fonts. Icons won't work without them. https://github.com/ryanoasis/nerd-fonts/ - -" This statusline looks exactly like Vim Airline (even more customizable & powerful) & loads faster than Vim airline. Only take few ms to load. - -" STARTUP TIME - With Vim Airline - ~250ms. With this statusline - ~100ms. Without any statusline - ~98ms. - -" Add all of this at the end of your vimrc OR Create separate file like 'statusline.vim' & 'colorsgroup.vim' & source those files in your main vimrc. -" e.g. source "~/.config/vim/statusline.vim" - - - - " statusline.vim -" NOTE: This has been edited to fit my needs and is intended to be autoloaded in the autoload directory: "~/.vim/autoload/statusline.vim" - if exists('g:loaded_statusline') | finish | endif let g:loaded_statusline = 1 -" Color highlighting groups -" Add this AFTER `colorscheme` option in your vimrc. Otherwise your colorscheme will clear these highlightings. -" OR use ColorScheme autocommand. VERY IMPORTANT. +" --- Detect Nerd Fonts --- +function! s:HasNerdFonts() + if exists('g:statusline_nerd_fonts') + return g:statusline_nerd_fonts + endif + + if executable('fc-list') + let l:output = system('fc-list | grep -i nerd') + if len(split(l:output, '\n')) > 0 + return 1 + endif + endif + + return 0 +endfunction -" Color pallet -" Green - #2BBB4F (BG) - #080808 (FG) -" Blue - #4799EB -" Violet - #986FEC -" Yellow - #D7A542 -" Orange - #EB754D -" Grey1 - #202020 -" Grey - #303030 +let g:statusline_has_nerd_fonts = s:HasNerdFonts() -" Define color variables +" --- Color Palette --- let g:StslineColorGreen = '#2BBB4F' let g:StslineColorBlue = '#4799EB' let g:StslineColorViolet = '#986FEC' let g:StslineColorYellow = '#D7A542' let g:StslineColorOrange = '#EB754D' - let g:StslineColorLight = '#C0C0C0' let g:StslineColorDark = '#080808' let g:StslineColorDark1 = '#181818' -let g:StslineColorDark2 = '#202020' +let g:StslineColorDark2 = 'NONE' let g:StslineColorDark3 = '#303030' -" Define colors let g:StslineBackColor = g:StslineColorDark2 let g:StslineOnBackColor = g:StslineColorLight -"let g:StslinePriColor = g:StslineColorGreen +let g:StslinePriColor = g:StslineColorGreen let g:StslineOnPriColor = g:StslineColorDark let g:StslineSecColor = g:StslineColorDark3 let g:StslineOnSecColor = g:StslineColorLight -" Create highlight groups -execute 'highlight StslineSecColorFG guifg=' . g:StslineSecColor ' guibg=' . g:StslineBackColor -execute 'highlight StslineSecColorBG guifg=' . g:StslineColorLight ' guibg=' . g:StslineSecColor -execute 'highlight StslineBackColorBG guifg=' . g:StslineColorLight ' guibg=' . g:StslineBackColor -execute 'highlight StslineBackColorFGSecColorBG guifg=' . g:StslineBackColor ' guibg=' . g:StslineSecColor -execute 'highlight StslineSecColorFGBackColorBG guifg=' . g:StslineSecColor ' guibg=' . g:StslineBackColor -execute 'highlight StslineModColorFG guifg=' . g:StslineColorYellow ' guibg=' . g:StslineBackColor - -" Statusline -" Enable statusline -set laststatus=2 -" Disable showmode - i.e. Don't show mode like --INSERT-- in current statusline. -set noshowmode - -" Enable GUI colors for terminals (Some terminals may not support this, so you'll have to *manually* set color pallet for tui colors.) -set termguicolors - - - -" Understand statusline elements - -" %{StslineMode()} = Output of a function -" %#StslinePriColorBG# = Highlight group -" %F, %c, etc. are variables which contain value like - current file path, current colums, etc. -" %{&readonly?\"\ \":\"\"} = If file is readonly ? Then "Lock icon" Else : "Nothing" -" %{get(b:,'coc_git_status',b:GitBranch)} = If b:coc_git_status efists, then it's value, else value of b:GitBranch -" &filetype, things starting with & are also like variables with info. -" \ - Is for escaping a space. \" is for escaping a double quote. -" %{&fenc!='utf-8'?\"\ \":''} = If file encoding is NOT!= 'utf-8' ? THEN output a "Space" else : no character - -let space = ' ' - -" Define active statusline -function! autoload#statusline#ActivateStatusline() abort - call autoload#statusline#GetFileType() - setlocal statusline=%#StslinePriColorBG#\ \ %{autoload#statusline#StslineMode()}\ %#StslineSecColorBG#%{get(b:,'coc_git_status',b:GitBranch)}%{get(b:,'coc_git_blame','')}%#StslineBackColorFGPriColorBG#%#StslinePriColorFG#\ %{&readonly?\"\ \":\"\"}%F\ %#StslineModColorFG#%{&modified?\"\ \":\"\"}%=%#StslinePriColorFG#\ %{b:FiletypeIcon}%{&filetype}\ %#StslineSecColorFG#%#StslineSecColorBG#%{&fenc!='utf-8'?\"\ \":''}%{&fenc!='utf-8'?&fenc:''}%{&fenc!='utf-8'?\"\ \":''}%#StslinePriColorFGSecColorBG#%#StslinePriColorBG#\ %p\%%\ %#StslinePriColorBGBold#%l%#StslinePriColorBG#/%L\ :%c\ \ %#{space} -endfunction - -" Define Inactive statusline -function! autoload#statusline#DeactivateStatusline() abort - if !exists("b:GitBranch") || b:GitBranch == '' - setlocal statusline=%#StslineSecColorBG#\ INACTIVE\ %#StslineSecColorBG#%{get(b:,'coc_git_statusline',b:GitBranch)}%{get(b:,'coc_git_blame','')}%#StslineBackColorFGSecColorBG#%#StslineBackColorBG#\ %{&readonly?\"\ \":\"\"}%F\ %#StslineModColorFG#%{&modified?\"\ \":\"\"}%=%#StslineBackColorBG#\ %{b:FiletypeIcon}%{&filetype}\ %#StslineSecColorFGBackColorBG#%#StslineSecColorBG#\ %p\%%\ %l/%L\ :%c\ - else - setlocal statusline=%#StslineSecColorBG#%{get(b:,'coc_git_statusline',b:GitBranch)}%{get(b:,'coc_git_blame','')}%#StslineBackColorFGSecColorBG#%#StslineBackColorBG#\ %{&readonly?\"\ \":\"\"}%F\ %#StslineModColorFG#%{&modified?\"\ \":\"\"}%=%#StslineBackColorBG#\ %{b:FiletypeIcon}%{&filetype}\ %#StslineSecColorFGBackColorBG#%#StslineSecColorBG#\ %p\%%\ %l/%L\ :%c\ - endif -endfunction +" --- Highlight Groups --- +" Initial setup of highlight groups (will be updated by UpdateStslineColors) +execute 'highlight StslinePriColorBG guifg=' . g:StslineOnPriColor . ' guibg=' . g:StslinePriColor +execute 'highlight StslineSecColorFG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor +execute 'highlight StslineSecColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineSecColor +execute 'highlight StslineBackColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineBackColor +execute 'highlight StslineBackColorFGSecColorBG guifg=' . g:StslineBackColor . ' guibg=' . g:StslineSecColor +execute 'highlight StslineSecColorFGBackColorBG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor +execute 'highlight StslineModColorFG guifg=' . g:StslineColorYellow . ' guibg=' . g:StslineBackColor +execute 'highlight StslinePriColorBG_SecColorBG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor +execute 'highlight StslineModeSep guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor +execute 'highlight StslineGitSep guifg=' . g:StslineSecColor . ' guibg=' . g:StslineColorDark2 + +" --- Statusline Settings --- +if has('nvim') + set laststatus=3 +else + set laststatus=2 +endif + +"set noshowmode +"set termguicolors + +let space = '' " Get Statusline mode & also set primary color for that mode function! autoload#statusline#StslineMode() abort @@ -113,28 +77,30 @@ function! autoload#statusline#StslineMode() abort let b:CurrentMode = 'INSERT ' elseif l:CurrentMode ==# 'c' let g:StslinePriColor = g:StslineColorYellow - let b:CurrentMode = 'COMMAND ' + let b:CurrentMode = 'COMMAND' elseif l:CurrentMode ==# 'v' let g:StslinePriColor = g:StslineColorBlue let b:CurrentMode = 'VISUAL ' elseif l:CurrentMode ==# '\<C-v>' let g:StslinePriColor = g:StslineColorBlue - let b:CurrentMode = 'V-BLOCK ' + let b:CurrentMode = 'V-BLOCK' elseif l:CurrentMode ==# 'V' let g:StslinePriColor = g:StslineColorBlue let b:CurrentMode = 'V-LINE ' elseif l:CurrentMode ==# 'R' let g:StslinePriColor = g:StslineColorViolet - let b:CurrentMode = 'REPLACE ' + let b:CurrentMode = 'REPLACE' elseif l:CurrentMode ==# 's' let g:StslinePriColor = g:StslineColorBlue let b:CurrentMode = 'SELECT ' elseif l:CurrentMode ==# 't' let g:StslinePriColor = g:StslineColorYellow - let b:CurrentMode = 'TERM ' + let b:CurrentMode = 'TERM ' elseif l:CurrentMode ==# '!' let g:StslinePriColor = g:StslineColorYellow - let b:CurrentMode = 'SHELL ' + let b:CurrentMode = 'SHELL ' + else + let g:StslinePriColor = g:StslineColorGreen endif call autoload#statusline#UpdateStslineColors() @@ -142,86 +108,160 @@ function! autoload#statusline#StslineMode() abort return b:CurrentMode endfunction -" Update colors. Recreate highlight groups with new Primary color value. function! autoload#statusline#UpdateStslineColors() abort execute 'highlight StslinePriColorBG guifg=' . g:StslineOnPriColor . ' guibg=' . g:StslinePriColor execute 'highlight StslinePriColorBGBold guifg=' . g:StslineOnPriColor . ' guibg=' . g:StslinePriColor . ' gui=bold' execute 'highlight StslinePriColorFG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineBackColor execute 'highlight StslinePriColorFGSecColorBG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor - execute 'highlight StslineSecColorFGPriColorBG guifg=' . g:StslineSecColor . ' guibg=' . g:StslinePriColor - - if !exists("b:GitBranch") || b:GitBranch == '' - execute 'highlight StslineBackColorFGPriColorBG guifg=' . g:StslineBackColor . ' guibg=' . g:StslinePriColor - endif + execute 'highlight StslineModeSep guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor + execute 'highlight StslineGitSep guifg=' . g:StslineSecColor . ' guibg=' . g:StslineColorDark2 + execute 'highlight StslineSecColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineSecColor + execute 'highlight StslineBackColorBG guifg=' . g:StslineColorLight . ' guibg=' . g:StslineBackColor + execute 'highlight StslineBackColorFGSecColorBG guifg=' . g:StslineBackColor . ' guibg=' . g:StslineSecColor + execute 'highlight StslineSecColorFGBackColorBG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor + execute 'highlight StslineModColorFG guifg=' . g:StslineColorYellow . ' guibg=' . g:StslineBackColor + execute 'highlight StslinePriColorBG_SecColorBG guifg=' . g:StslinePriColor . ' guibg=' . g:StslineSecColor + execute 'highlight StslineSecColorFG guifg=' . g:StslineSecColor . ' guibg=' . g:StslineBackColor endfunction -" Get git branch name function! autoload#statusline#GetGitBranch() abort - let b:GitBranch = "" + let b:GitBranch = '' try let l:dir = expand('%:p:h') let l:gitrevparse = system("git -C ".l:dir." rev-parse --abbrev-ref HEAD") if !v:shell_error - let b:GitBranch = " " . substitute(l:gitrevparse, '\n', '', 'g') . " " - execute 'highlight StslineBackColorFGPriColorBG guifg=' . g:StslineBackColor . ' guibg=' . g:StslineSecColor + let icon = g:statusline_has_nerd_fonts ? ' ' : ' [git] ' + let b:GitBranch = icon . substitute(l:gitrevparse, '\n', '', 'g') . ' ' endif catch endtry endfunction -" Get filetype & custom icon. Put your most used file types first for optimized performance. function! autoload#statusline#GetFileType() abort - if &filetype ==# 'typescript' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'html' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'scss' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'css' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'javascript' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'javascriptreact' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'markdown' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'sh' || &filetype ==# 'zsh' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'vim' - let b:FiletypeIcon = ' ' - elseif &filetype ==# '' + if !g:statusline_has_nerd_fonts let b:FiletypeIcon = '' - elseif &filetype ==# 'rust' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'ruby' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'cpp' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'c' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'go' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'lua' - let b:FiletypeIcon = ' ' - elseif &filetype ==# 'haskel' - let b:FiletypeIcon = ' ' + return + endif + if &filetype ==# 'typescript' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'html' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'scss' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'css' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'javascript' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'javascriptreact' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'markdown' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'sh' || &filetype ==# 'zsh' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'vim' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'rust' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'ruby' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'cpp' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'c' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'go' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'lua' | let b:FiletypeIcon = ' ' + elseif &filetype ==# 'haskell' | let b:FiletypeIcon = ' ' + else | let b:FiletypeIcon = ' ' + endif +endfunction + +function! autoload#statusline#ActivateStatusline() abort + call autoload#statusline#GetFileType() + call autoload#statusline#GetGitBranch() " Ensure git branch is updated + + let current_mode_str = autoload#statusline#StslineMode() + call autoload#statusline#UpdateStslineColors() + + let readonly_icon = g:statusline_has_nerd_fonts ? ' ' : '[RO] ' + let modified_icon = g:statusline_has_nerd_fonts ? ' ' : '[+] ' + let git_sep = g:statusline_has_nerd_fonts ? '' : ' ' + let file_sep1 = g:statusline_has_nerd_fonts ? ' ' : ' ' + let file_sep2 = g:statusline_has_nerd_fonts ? '' : '' + + " Get dynamic parts as simple strings + let git_status_str = get(b:, "coc_git_status", get(b:, "GitBranch", "")) + let git_blame_str = get(b:, "coc_git_blame", "") + let filetype_icon_str = get(b:, "FiletypeIcon", "") + let file_encoding_str = '' + if &fenc != "utf-8" + let file_encoding_str = &fenc . ' ' + endif + + " Build the statusline as a static string + let l:statusline = '' + + let l:statusline .= '%#StslinePriColorBG# ' . current_mode_str . '' + let l:statusline .= '%#StslineModeSep#' . git_sep + let l:statusline .= '%#StslineSecColorBG#' . git_status_str . git_blame_str + let l:statusline .= '%#StslineGitSep#' . git_sep + + " File info (Readonly, Modified, Filename) + let l:statusline .= '%#StslinePriColorFG#' + if &readonly + let l:statusline .= readonly_icon + endif + let l:statusline .= ' %F ' + if &modified + let l:statusline .= modified_icon + endif + + " Right align everything after this + let l:statusline .= '%=' + + " Right side (Filetype, Encoding, Position) + let l:statusline .= '%#StslinePriColorFG# ' . filetype_icon_str . '%y' + let l:statusline .= '%#StslineSecColorFG#' . file_sep1 + "let l:statusline .= '%#StslineSecColorBG# ' . file_encoding_str + let l:statusline .= '%#StslinePriColorFGSecColorBG#' . file_sep2 + let l:statusline .= '%#StslinePriColorBG# %p%% %#StslinePriColorBGBold#%l%#StslinePriColorBG#/%L :%c ' + let l:statusline .= '%#StslineBackColorBG#' + + " Set the statusline for the current buffer + let &l:statusline = l:statusline +endfunction + +function! autoload#statusline#DeactivateStatusline() abort + let git_sep = g:statusline_has_nerd_fonts ? '' : '' + let readonly_icon = g:statusline_has_nerd_fonts ? ' ' : '[RO] ' + let modified_icon = g:statusline_has_nerd_fonts ? ' ' : '[+] ' + + " NOTE: This DeactivateStatusline function still uses %{} for dynamic parts. + " If you encounter general E518 or other issues related to %{} expressions, + " you will need to refactor this function to build a static string + " similar to how ActivateStatusline now does it. + if !exists("b:GitBranch") || b:GitBranch == '' + let statusline = + \ '%#StslineSecColorBG# INACTIVE ' . + \ '%{get(b:,"coc_git_statusline",b:GitBranch)}%{get(b:,"coc_git_blame","")}' . + \ '%#StslineBackColorFGSecColorBG#' . git_sep . + \ '%#StslineBackColorBG# %{&readonly?"' . readonly_icon . '":""}%F ' . + \ '%#StslineModColorFG#%{&modified?"' . modified_icon . '":""}' . + \ '%=%#StslineBackColorBG# %{b:FiletypeIcon}%{&filetype}' . + \ '%#StslineSecColorFGBackColorBG# | %p%% %l/%L :%c' else - let b:FiletypeIcon = ' ' + let statusline = + \ '%#StslineSecColorBG# %{get(b:,"coc_git_statusline",b:GitBranch)}%{get(b:,"coc_git_blame","")}' . + \ '%#StslineBackColorFGSecColorBG#' . git_sep . + \ '%#StslineBackColorBG# %{&readonly?"' . readonly_icon . '":""}%F ' . + \ '%#StslineModColorFG#%{&modified?"' . modified_icon . '":""}' . + \ '%=%#StslineBackColorBG# %{b:FiletypeIcon}%{&filetype}' . + \ '%#StslineSecColorFGBackColorBG# | %p%% %l/%L :%c' endif + + execute 'setlocal statusline=' . substitute(statusline, '"', '\\"', 'g') endfunction -" Automatically update git branch name when entering a buffer -augroup GetGitBranch +augroup StatuslineGit autocmd! autocmd BufEnter * call autoload#statusline#GetGitBranch() augroup END -" Set active / inactive statusline when entering or leaving a buffer augroup SetStsline - autocmd! - autocmd BufEnter,WinEnter * call autoload#statusline#ActivateStatusline() - autocmd BufLeave,WinLeave * call autoload#statusline#DeactivateStatusline() + autocmd! + autocmd BufEnter,WinEnter * call autoload#statusline#ActivateStatusline() + autocmd ModeChanged * call autoload#statusline#ActivateStatusline() augroup END -call autoload#statusline#ActivateStatusline() +augroup StatuslineAutoReload + autocmd! + autocmd BufWritePost statusline.vim source <afile> | call autoload#statusline#ActivateStatusline() +augroup END +"call autoload#statusline#ActivateStatusline() |
