From 79d2a20b1ff35be27e57e0362c6d87b337f2ffa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 3 Dec 2021 09:20:03 +0100 Subject: [PATCH] Fixed visible whitespace handling --- cfg/05-visible-whitespace.vim | 43 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/cfg/05-visible-whitespace.vim b/cfg/05-visible-whitespace.vim index d22c137..f5a4bc2 100644 --- a/cfg/05-visible-whitespace.vim +++ b/cfg/05-visible-whitespace.vim @@ -3,37 +3,36 @@ " Trailing spaces are visible in normal or visual mode, but hidden in insert " mode. All whitespace can be made visible using ow -let s:Settings = { -\ 'tab' : [ " " , "» " ] , -\ 'nbsp' : [ " " , "⚠" ] , -\ 'space' : [ " " , "·" ] , -\ 'eol' : [ " " , "¶" ] , -\ } -let s:VisibleTabs = 0 +let s:VisibleWhitespace = 0 +let s:VisibleTrail = 1 -function! s:UpdateListChars(type,value) - let lc = filter( split( &l:listchars , "," ) , "v:val !~ '^" . a:type . ":'" ) + [ a:type . ":" . a:value ] - let &l:listchars = join( lc , "," ) +function! s:UpdateListChars() + if s:VisibleWhitespace + set listchars=tab:»\ ,nbsp:⚠,space:·,eol:¶ + else + set listchars=tab:\ \ , + endif + if s:VisibleTrail + set listchars+=trail:• + endif endfunction -function! s:ApplyWhitespaceSettings() - for k in keys(s:Settings) - call s:UpdateListChars( k , s:Settings[k][s:VisibleTabs] ) - endfor +function! s:ToggleWhitespace() + let s:VisibleWhitespace = 1 - s:VisibleWhitespace + call s:UpdateListChars() endfunction -function! ToggleVisibleWhitespace() - let s:VisibleTabs = 1 - s:VisibleTabs - call s:ApplyWhitespaceSettings() +function! s:SetVisibleTrail(trail) + let s:VisibleTrail = a:trail + call s:UpdateListChars() endfunction set list -set listchars="" -call s:ApplyWhitespaceSettings() +call s:UpdateListChars() +nnoremap ow :call ToggleWhitespace() -nnoremap ow :call ToggleVisibleWhitespace() augroup TrailingWhitespace autocmd! - autocmd InsertEnter * :call UpdateListChars( "trail" , " " ) - autocmd InsertLeave * :call UpdateListChars( "trail" , "•" ) + autocmd InsertEnter * :call SetVisibleTrail(0) + autocmd InsertLeave * :call SetVisibleTrail(1) augroup END