Lokaltog/vim-powerline — Issue #26: Wiki with the ability to share custom segments.
Author: YANOUSHek
Created: 2012-01-13 15:22:07+00:00
State: open

Hi,

I've written a simple segment for the Powerline that shows when you have trailing whitespace in your file. Is there any place where people can share those segments?

Regards,
Janusz

P.S. Here's the code:

Add this function to your .vimrc (stolen from http://got-ravings.blogspot.com/2008/10/vim-pr0n-statusline-whitespace-flags.html):

```vim
"recalculate the trailing whitespace warning when idle, and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning

"return '···' if trailing white space is detected
"return '' otherwise
function! StatuslineTrailingSpaceWarning()
if !exists("b:statusline_trailing_space_warning")
if search('\s\+$', 'nw') != 0
let b:statusline_trailing_space_warning = '···'
else
let b:statusline_trailing_space_warning = ''
endif
endif
return b:statusline_trailing_space_warning
endfunction
```

Add this segment your statusline:

```vim
\ Pl#Segment(' %{StatuslineTrailingSpaceWarning()}',
\ Pl#HiCurrent( Pl#FG(255), Pl#BG( 1)),
\ Pl#HiInsert( Pl#FG( 23), Pl#BG(231)),
\ Pl#HiNonCurrent(Pl#FG(255), Pl#BG( 1))
```