Skip to content

Instantly share code, notes, and snippets.

@tasmo
Last active August 29, 2022 01:02
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tasmo/bb79473aedb6797f016522109884ad9a to your computer and use it in GitHub Desktop.
Save tasmo/bb79473aedb6797f016522109884ad9a to your computer and use it in GitHub Desktop.
set noshowmode
set noruler
" Get current filetype
function! CheckFT(filetype)
if a:filetype == ''
return '-'
else
return tolower(a:filetype)
endif
endfunction
function! AleStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'OK' : printf(
\ '%dW %dE',
\ all_non_errors,
\ all_errors
\)
endfunction
function! GitGutterStatus()
let [a,m,r] = GitGutterGetHunkSummary()
return printf('+%d ~%d -%d', a, m, r)
endfunction
" set colors for statusline based on mode
function! DetectMode(mode)
if empty($DISPLAY)
let left=""
let right=""
else
let left=""
let right=""
end
let statusline=""
if a:mode == 'n'
let statusline .= "%#ModeNFGCS#\ " . left
let statusline .= "%#ModeNFGC#\ NORMAL\ "
let statusline .= "%#ModeNFGCS#" . right . "\ " . left
let statusline .= "%#ModeNFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode == 'i'
let statusline .= "%#ModeIFGCS#\ " . left
let statusline .= "%#ModeIFGC#\ INSERT\ "
let statusline .= "%#ModeIFGCS#" . right . "\ " . left
let statusline .= "%#ModeIFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode == 'R'
let statusline .= "%#ModeRFGCS#\ " . left
let statusline .= "%#ModeRFGC#\ REPLACE\ "
let statusline .= "%#ModeRFGCS#" . right . "\ " . left
let statusline .= "%#ModeRFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode ==# 'v'
let statusline .= "%#ModeVFGCS#\ " . left
let statusline .= "%#ModeVFGC#\ VISUAL\ "
let statusline .= "%#ModeVFGCS#" . right . "\ " . left
let statusline .= "%#ModeVFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode ==# 'V'
let statusline .= "%#ModeVFGCS#\ " . left
let statusline .= "%#ModeVFGC#\ VISUAL\ "
let statusline .= "%#ModeVFGCS#" . right . "\ " . left
let statusline .= "%#ModeVFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode ==# ''
let statusline .= "%#ModeVFGCS#\ " . left
let statusline .= "%#ModeVFGC#\ VISUAL\ "
let statusline .= "%#ModeVFGCS#" . right . "\ " . left
let statusline .= "%#ModeVFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode ==# 'c'
let statusline=""
let statusline .= "%#ModeCFGCS#\ " . left
let statusline .= "%#ModeCFGC#\ COMMAND\ "
let statusline .= "%#ModeCFGCS#" . right . "\ " . left
let statusline .= "%#ModeCFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode ==# 't'
let statusline .= "%#ModeTFGCS#\ " . left
let statusline .= "%#ModeTFGC#\ TERMINAL\ "
let statusline .= "%#ModeTFGCS#" . right . "\ " . left
let statusline .= "%#ModeTFGC#%[%n\ ̷%{bufnr('$')}\ "
elseif a:mode == 'v' || a:mode == 'V' || a:mode == '^V' || a:mode == 's' || a:mode == 'S' || a:mode == '^S'
let statusline .= "%#ModeVFGCS#\ " . left
let statusline .= "%#ModeVFGC#\ VISUAL\ "
let statusline .= "%#ModeVFGCS#" . right . "\ " . left
let statusline .= "%#ModeVFGC#%[%n\ ̷%{bufnr('$')}\ "
endif
if &mod == 1
let statusline .= "%#Modified#\ %.20f\ ⁺%#ModifiedS#" . right . "\ "
else
let statusline .= "%#Buffer#\ %.20f\ %#BufferS#" . right . "\ "
endif
let statusline .= "%="
if exists('*fugitive#statusline') || &rtp =~ 'GitGutter'
if exists('*fugitive#statusline')
let statusline .= "%#BufferS#" . left . "%#SLGreen#\ %{FugitiveHead()}\ "
else
let statusline .= "%#BufferS#" . left
endif
if &rtp =~ 'GitGutter'
let statusline .= "%#SLBlue#\ %{GitGutterStatus()}\ %#BufferS#" . right . "\ "
else
let statusline .= "%#BufferS#" . right . "\ "
endif
endif
let statusline .= "%#BufferS#" . left . "%#Buffer#\ %{CheckFT(&filetype)}\ "
if &rtp =~ 'ale'
if AleStatus() == "OK"
let statusline .= "%#SLLimiter#│%#CursorStatus#\ %{AleStatus()}\ %#BufferS#" . right . "\ "
else
let statusline .= "\ %#BufferError#\ %{AleStatus()}\ %#BufferErrorS#" . right . "\ "
endif
else
let statusline .= "%#BufferS#" . right . "\ "
endif
let statusline .= "%#BufferS#" . left . "%#CursorStatus#\ %-8.(%l,%c%)%#ModeNFGC#\ %P\ %#ModeNFGCS#" . right . "\ "
return statusline
return ' '
endfunction
set laststatus=2
set statusline=%!DetectMode(mode())
" vim:set ft=vim et sw=2:
@ChrisMGeo
Copy link

I came here from reddit. How do I make the rounded corners in the statusline? I'm using a nerd font version of Iosevka if that helps.

@tasmo
Copy link
Author

tasmo commented Dec 1, 2020

I use the latest standard version of Iosevka. Maybe the Nerdfont does not have the rounded blocks.

@ChrisMGeo
Copy link

I think I managed to do it, basically I use nvim-qt so if empty($DISPLAY) seems to be true for me always, so I removed the if from my script.

@tasmo
Copy link
Author

tasmo commented Dec 1, 2020

Good finding.

@gj1118
Copy link

gj1118 commented Dec 3, 2020

I came from Reddit as well. I am a new VIM user. Can you please tell me how to use this ? I am using NVIM and I just pasted all the above in my init.vim , but there are bunch of errors happening as soon as my launch my instance of Neovim. Please suggest.

Thanks

@tasmo
Copy link
Author

tasmo commented Dec 4, 2020

but there are bunch of errors happening as soon as my launch my instance of Neovim

Without knowing the errors I just could guess badly. Please give more details.

@ChrisMGeo
Copy link

I came from Reddit as well. I am a new VIM user. Can you please tell me how to use this ? I am using NVIM and I just pasted all the above in my init.vim , but there are bunch of errors happening as soon as my launch my instance of Neovim. Please suggest.

Thanks

Install ALE and GitGutter even if you dont use them. This script depends on them. GitGutter is a must but ALE for my workflow isn't. I was thinking of editing the script further to be independent of ale but I dont know much vimscript. Maybe I might make one later

@tasmo
Copy link
Author

tasmo commented Dec 5, 2020

Thank you for the input. Hopefully it will work now. If not, please keep hinting what is wrong.

Just please keep in mind that this is not an official "package" I maintain.

@Matsuuu
Copy link

Matsuuu commented Dec 9, 2020

Thanks a lot for this! It inspired me to write my own statusline.

Where did you get the rounded circle unicodes, and do you have the exact codes?

I found a pair, but they were smaller. I could use a pair that is a little bit smaller, but i'm guessing that isn't possible

@tasmo
Copy link
Author

tasmo commented Dec 9, 2020

Nice to hear that it inspires you for an own statusline. :)

The characters are in the line 37 and line 38. The unicodes are U+E0B6 for left and U+E0B4 for right. Both characters are in the private use area of Iosevka.

@Matsuuu
Copy link

Matsuuu commented Dec 9, 2020

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment