Monday, December 30, 2013

Re: display the title of current fold in the statusline

I just did it! :) A big thanks for the tips again!

highlight link StatFname StatusLine
highlight link StatFenc StatusLineNC
highlight link StatPath LineNr
highlight link StatLnum StatusLineNC

highlight link StatFnameINS StatusLine
highlight link StatFencINS StatPath
highlight link StatPathINS ModeMsg
highlight link StatLnumINS StatPath

highlight link StatFnameNC StatusLineNC
highlight link StatFencNC StatFnameNC
highlight link StatPathNC StatFnameNC
highlight link StatLnumNC StatFnameNC

let &statusline = "%!StatusLine( '' )"

function StatusLine( mode )

let statusline = '%#StatFname' . a:mode . '#'
let statusline .= '%w%t%r%m '

let statusline .= '%#StatFenc' . a:mode . '# '
let statusline .= '[' . (&binary ? 'binary' : (&fenc . (&bomb ? '-bom' : ''))) . ' ' . &ff . '] '

let statusline .= '%#StatPath' . a:mode . '# '
let statusline .= '%<'

let path = expand( '%:p:h' ) . (has( 'win32' ) ? '\' : '/')

if (a:mode == 'INS') && (foldlevel( '.' ) > 0)

let save_foldtext = &foldtext
set foldtext=StatFoldText()

if foldclosed( '.' ) < 0
foldclose
let statusline .= foldtextresult( foldclosed( '.' ) )
foldopen
else
let statusline .= foldtextresult( '.' )
endif

let &foldtext = save_foldtext

else

let statusline .= path

endif

let statusline .= '%='

let statusline .= '%#StatLnum' . a:mode . '# '
let statusline .= '%3v | %5l/%L (%3p%%)'

return statusline

endfunction

function StatFoldText()
return substitute( foldtext(), '^.\{-}: \|\s\+$', '', 'g' )
endfunction

autocmd WinEnter,InsertLeave * let &l:statusline = "%!StatusLine( '' )"
autocmd InsertEnter,InsertChange * let &l:statusline = "%!StatusLine( 'INS' )"
autocmd WinLeave * let &l:statusline = "%!StatusLine( 'NC' )"

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: