diff options
Diffstat (limited to 'common/nvim/autoload')
| -rwxr-xr-x | common/nvim/autoload/statusline.vim | 267 | ||||
| -rwxr-xr-x | common/nvim/autoload/utils.vim | 238 |
2 files changed, 505 insertions, 0 deletions
diff --git a/common/nvim/autoload/statusline.vim b/common/nvim/autoload/statusline.vim new file mode 100755 index 0000000..bf5f972 --- /dev/null +++ b/common/nvim/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/common/nvim/autoload/utils.vim b/common/nvim/autoload/utils.vim new file mode 100755 index 0000000..d92b771 --- /dev/null +++ b/common/nvim/autoload/utils.vim @@ -0,0 +1,238 @@ +" Toggle Zoom +function! utils#ZoomToggle() + if exists('t:zoomed') && t:zoomed + execute t:zoom_winrestcmd + let t:zoomed = 0 + else + let t:zoom_winrestcmd = winrestcmd() + resize + vertical resize + let t:zoomed = 1 + endif +endfunction +"command! ZoomToggle call ZoomToggle() + + +"------------------------------------------------- + +" Toggle DiagnosticsOpenFloat +" Enable DiagnosticsOpenFloat by default +"let g:DiagnosticsOpenFloat = 1 +" +"" Define the autocmd group on startup +"augroup OpenFloat +" autocmd! +" autocmd CursorHold * lua if vim.g.DiagnosticsOpenFloat then vim.diagnostic.open_float(nil, { focusable = false }) end +"augroup END + +" Toggle function +function! utils#ToggleDiagnosticsOpenFloat() + " Flip the toggle + let g:DiagnosticsOpenFloat = !get(g:, 'DiagnosticsOpenFloat', 1) +endfunction + +" Command to toggle +command! ToggleDiagnosticsOpenFloat call utils#ToggleDiagnosticsOpenFloat() + +"------------------------------------------------- + +" Toggle transparency +let t:is_transparent = 0 +function! utils#Toggle_transparent_background() + if t:is_transparent == 0 + hi Normal guibg=#111111 ctermbg=black + let t:is_transparent = 1 + else + hi Normal guibg=NONE ctermbg=NONE + let t:is_transparent = 0 + endif +endfunction +"nnoremap <leader>tb :call Toggle_transparent_background()<CR> + + +"------------------------------------------------- + +" Toggle statusline +let s:hidden_all = 0 +function! utils#ToggleHiddenAll() + if s:hidden_all == 0 + let s:hidden_all = 1 + set noshowmode + set noruler + set laststatus=0 + set noshowcmd + else + let s:hidden_all = 0 + set showmode + set ruler + set laststatus=2 + set showcmd + endif +endfunction +"nnoremap <S-h> :call ToggleHiddenAll()<CR> + + +"------------------------------------------------- + +" Open last closed buffer +function! utils#OpenLastClosed() + let last_buf = bufname('#') + if empty(last_buf) + echo "No recently closed buffer found" + return + endif + let result = input("Open ". last_buf . " in (n)ormal (v)split, (t)ab or (s)plit ? (n/v/t/s) : ") + if empty(result) || (result !=# 'v' && result !=# 't' && result !=# 's' && result !=# 'n') + return + endif + if result ==# 't' + execute 'tabnew' + elseif result ==# 'v' + execute "vsplit" + elseif result ==# 's' + execute "split" + endif + execute 'b ' . last_buf +endfunction + + +"------------------------------------------------- + +" Toggle Diff +let g:diff_is_open = 0 + +function! utils#ToggleDiff() + if g:diff_is_open + windo diffoff + let g:diff_is_open = 0 + else + windo diffthis + let g:diff_is_open = 1 + endif +endfunction + + +"------------------------------------------------- + +" Verbose Toggle +function! utils#VerboseToggle() + if !&verbose + set verbosefile=~/.config/nvim/verbose.log + set verbose=15 + else + set verbose=0 + set verbosefile= + endif +endfunction + + +"------------------------------------------------- + +" Jump List +function! utils#GotoJump() + jumps + let j = input("Please select your jump: ") + if j != '' + let pattern = '\v\c^\+' + if j =~ pattern + let j = substitute(j, pattern, '', 'g') + execute "normal " . j . "\<c-i>" + else + execute "normal " . j . "\<c-o>" + endif + endif +endfunction + + +"------------------------------------------------- + +" Disable annoying auto line break +fu! utils#DisableBr() + set wrap + set linebreak + set nolist " list disables linebreak + set textwidth=0 + set wrapmargin=0 + set formatoptions-=t +endfu + +" Disable line breaks for all file types +autocmd! BufNewFile,BufRead *.* call utils#DisableBr() + + +"------------------------------------------------- + +" Annoying timestamp issue on write (The file has been changed since reading it...) +"function! utils#ProcessFileChangedShell() +" if v:fcs_reason == 'mode' || v:fcs_reason == 'time' +" let v:fcs_choice = '' +" else +" let v:fcs_choice = 'ask' +" endif +"endfunction +"autocmd FileChangedShell <buffer> call utils#ProcessFileChangedShell() +" +"let lastline = line('$') +"let bufcontents = getline(1, lastline) +"edit! +"call setline(1, bufcontents) +"if line('$') > lastline +" execute lastline+1.',$:d _' +"endif + +" Annoying timestamp issue on write (The file has been changed since reading it...) +function! utils#ProcessFileChangedShell() + if v:fcs_reason == 'mode' || v:fcs_reason == 'time' + let v:fcs_choice = '' + else + let v:fcs_choice = 'ask' + endif +endfunction + +" Triggered when the file is changed externally +autocmd FileChangedShell <buffer> call utils#ProcessFileChangedShell() + +" Triggered before writing the buffer to the file +autocmd BufWritePre <buffer> call utils#BeforeWrite() + +function! utils#BeforeWrite() + let lastline = line('$') + let bufcontents = getline(1, lastline) + edit! + call setline(1, bufcontents) + if line('$') > lastline + execute lastline+1.',$:d _' + endif +endfunction + + +"------------------------------------------------- + +" On The Fly Table mode +function! s:isAtStartOfLine(mapping) + let text_before_cursor = getline('.')[0 : col('.')-1] + let mapping_pattern = '\V' . escape(a:mapping, '\') + let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\') + return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$') +endfunction + + +"------------------------------------------------- + +" :Rename {newname} +function! utils#RenameFile() + let old_name = expand('%') + let new_name = input('New file name: ', expand('%'), 'file') + if new_name != '' && new_name != old_name + exec ':saveas ' . new_name + exec ':silent !rm ' . old_name + redraw! + endif +endfunction + +augroup obsidian + autocmd! + autocmd Filetype markdown set conceallevel=2 +augroup END + +"------------------------------------------------- |
