statusline mode/modified indicator

This commit is contained in:
ManjaroOne666 2018-03-16 19:56:24 +00:00
commit fd0056c650
2 changed files with 101 additions and 58 deletions

133
vimrc
View file

@ -249,19 +249,23 @@ iabbrev waht what
iabbrev tehn then
"}}}
" #statusline format{{{
" #statusline format
" isactive = 0 when inactive, 1 otherwise
" get status line{{{
function! GetStatus(isactive)
let l:divider='- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >'
let l:separator='%#StatusLineSeparator# '
let l:normal='%#StatusLineNormal#'
let l:active='%#StatusLineActive#'
let l:statusline=''
"}}}
" linter status{{{
let l:statusline.='%#InterfaceH2# %{LinterStatus()} %*'
"}}}
" file info{{{
if a:isactive == 1
let l:statusline.=l:active
@ -275,12 +279,14 @@ function! GetStatus(isactive)
let l:statusline.=l:separator
endif
"}}}
" current register{{{
if a:isactive
let l:statusline.=l:separator . l:active
let l:statusline.=' %#StatusLineActiveQuotes#"' . l:active . '%{v:register}%#StatusLineActiveQuotes#" '
endif
"}}}
" session status{{{
if a:isactive
let l:statusline.=l:separator . l:active
@ -288,51 +294,66 @@ function! GetStatus(isactive)
let l:statusline.=l:separator . l:active
endif
"}}}
" right/left separator{{{
" right/left divider{{{
" modified version
let l:color='StatusLineDivMod' . (a:isactive?'Active':'')
let l:statusline.=GetStatusFrag("&modified && mode() != 'i'", l:color, '%<', l:divider)
" unmodified version
let l:color='StatusLineDiv' . (a:isactive?'Active':'')
let l:statusline.=GetStatusFrag("!&modified && mode() != 'i'", l:color, '%<', l:divider)
" input mode version
if a:isactive
let l:statusline.='%#StatusLineDividerActive# %< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >' . l:separator . '%*'
else
let l:statusline.='%#StatusLineDivider# %< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >' . l:separator . '%*'
let l:statusline.=GetStatusFrag("mode() == 'i'", 'StatusLineDivInput', '%<', l:divider)
endif
let l:statusline.='%='
let l:statusline.=l:separator . '%*%='
"}}}
" path/filename.extension{{{
if a:isactive
let l:statusline.='%#StatusLineDirActive# '
let l:statusline.="%{expand('%:p:h:t')}/"
let l:statusline.='%#StatusLineFileActive#'
" modified flag {{{
" let l:statusline.='%#StatusLineMod#%M' . l:separator . '%*'
"}}}
let l:statusline.="%{expand('%:t:r')}"
" path/filename.extension{{{
if a:isactive
let l:statusline.='%#StatusLineDirActive# '
let l:statusline.="%{expand('%:p:h:t')}/"
let l:statusline.='%#StatusLineFileActive#'
let l:statusline.='%#StatusLineDotActive#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExtActive#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
let l:statusline.=' %*'
else
let l:statusline.='%#StatusLineDir# '
let l:statusline.="%{expand('%:p:h')}/"
let l:statusline.='%#StatusLineFile#'
let l:statusline.="%{expand('%:t:r')}"
let l:statusline.="%{expand('%:t:r')}"
let l:statusline.='%#StatusLineDotActive#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExtActive#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
let l:statusline.=' %*'
else
let l:statusline.='%#StatusLineDir# '
let l:statusline.="%{expand('%:p:h')}/"
let l:statusline.='%#StatusLineFile#'
let l:statusline.='%#StatusLineDot#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExt#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
let l:statusline.=' %*'
endif
let l:statusline.="%{expand('%:t:r')}"
let l:statusline.='%#StatusLineDot#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExt#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
let l:statusline.=' %*'
endif
"}}}
" modified flag {{{
let l:statusline.=l:separator . '%#StatusLineMod#%M' . l:separator . '%*'
"}}}
" file percentage{{{
let l:statusline.='%#InterfaceNormalDark#%P%*'
let l:statusline.=l:separator . '%#InterfaceNormalDark#%P%*'
return l:statusline
endfunction
"}}}
" status line autocommands{{{
augroup status
autocmd!
@ -342,6 +363,7 @@ augroup status
augroup END
"}}}}}}
" #autocommands{{{
" persistent folds
@ -389,24 +411,32 @@ augroup END
" #functions{{{
function! CheckLineEnding()
" TODO better name
function! GetStatusFrag(condition, colorname, conditionprefix, text) "{{{
let l:frag='%#' . a:colorname . '#'
let l:frag.=a:conditionprefix
let l:frag.='%{(' . a:condition . ")?'" . a:text . "':''}"
return l:frag
endfunction"}}}
function! CheckLineEnding() "{{{
:normal $
if getline('.')[col('.')-1] == ';' || getline('.')[col('.')-1] == ','
:startinsert
else
:startinsert!
endif
endfunction
endfunction"}}}
" get name of syntax item
function! SyntaxItem()
function! SyntaxItem() "{{{
return synIDattr(synID(line('.'),col('.'),1),'name') . ' -> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
endfunction
nnoremap <leader>p :echom SyntaxItem()<CR>
nnoremap <leader>p :echom SyntaxItem()<CR>"}}}
" devdocs DD
" https://gist.github.com/romainl/8d3b73428b4366f75a19be2dad2f0987#file-devdocs-vim
function! s:Get_env() abort
function! s:Get_env() abort "{{{
if has('win64') || has('win32') || has('win16')
return 'WINDOWS'
else
@ -422,10 +452,10 @@ let s:stub = s:cmds[<SID>Get_env()] . " 'http://devdocs.io/?q="
command! -nargs=* DD silent! call system(len(split(<q-args>, ' ')) == 0 ?
\ s:stub . &ft . ' ' . expand('<cword>') . "'" : len(split(<q-args>, ' ')) == 1 ?
\ s:stub . &ft . ' ' . <q-args> . "'" : s:stub . <q-args> . "'")
"}}}
" use ranger as file manager
if !exists('*RangerExplorer')
if !exists('*RangerExplorer')" {{{
function RangerExplorer()
exec 'silent !ranger --choosefile=/tmp/vim_ranger_current_file ' . expand('%:p:h')
if filereadable('/tmp/vim_ranger_current_file')
@ -435,7 +465,17 @@ if !exists('*RangerExplorer')
redraw!
endfun
map <Leader>ra :call RangerExplorer()<CR>
endif
endif"}}}
function! LinterStatus() 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', l:all_non_errors, l:all_errors)
endfunction
"}}}
"}}}
@ -501,17 +541,6 @@ let g:ale_html_htmlhint_options = '-c ~/.htmlhintrc --format=unix'
let g:ale_fixers = {'javascript': ['eslint']}
function! LinterStatus() 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', l:all_non_errors, l:all_errors)
endfunction
"nmap <silent> <C-k> <Plug>(ale_previous_wrap)
"nmap <silent> <C-j> <Plug>(ale_next_wrap)
" ultisnips
let g:UltiSnipsSnippetsDir="~/.vim/UltiSnips"
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.