vim/plugin/functions.vim

44 lines
1.4 KiB
VimL

" Fold Text
set foldtext=FoldText()
function! FoldText()
let l:line = getline(v:foldstart)
return l:line.' '.string(v:foldend - v:foldstart + 1).' lines '
endfunction
" Derived from http://stackoverflow.com/a/1333025
function! CloneHighlightGroupWithAttributes(group, new_group, attributes)
" Get group details, resolving group links.
redir => l:group
exe 'silent hi ' . a:group
redir END
while l:group =~? 'links to'
let l:index = stridx(l:group, 'links to') + len('links to')
let l:linked_group = strpart(l:group, l:index + 1)
redir => l:group
exe 'silent hi ' . l:linked_group
redir END
endwhile
" Get highlight parameters and existing remove attributes.
let l:parameters = matchlist(l:group, '\<xxx\>\s\+\(.*\)')[1]
let l:parameters = substitute(l:parameters, '\(c\?term\|gui\)=\w\+', '', 'g')
" Create the cloned highlight group with new attributes.
exe 'hi '.a:new_group.' '.l:parameters.
\' term='.a:attributes.' cterm='.a:attributes.' gui='.a:attributes
endfunction
function! s:Synstack()
for l:id in synstack(line('.'), col('.'))
let l:attributes = synIDattr(l:id, 'name')
let l:attr = synIDattr(l:id, 'fg')
if l:attr !=? ''
let l:attributes = l:attributes.' fg='.l:attr
endif
endfor
endfunction
command Synstack :call s:Synstack()
" Invoke terminal command without prompt and then redraw.
command! -nargs=+ Silent execute 'silent <args>' | redraw!