From e62de27044d3e18bbe6f5d3ab65afcea9afc93f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 7 Dec 2020 15:04:39 +0100 Subject: [PATCH] Improved visible whitespace stuff Median dots for spaces, pilcrow at end of lines --- cfg/05-visible-whitespace.vim | 37 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/cfg/05-visible-whitespace.vim b/cfg/05-visible-whitespace.vim index f3dfc30..d22c137 100644 --- a/cfg/05-visible-whitespace.vim +++ b/cfg/05-visible-whitespace.vim @@ -1,12 +1,14 @@ " Trailing spaces and visible tabs " " Trailing spaces are visible in normal or visual mode, but hidden in insert -" mode. Tabs can be displayed or hidden using T. +" mode. All whitespace can be made visible using ow -set list -set listchars="" -set listchars+=trail:• -set listchars+=tab:\ \ +let s:Settings = { +\ 'tab' : [ " " , "» " ] , +\ 'nbsp' : [ " " , "⚠" ] , +\ 'space' : [ " " , "·" ] , +\ 'eol' : [ " " , "¶" ] , +\ } let s:VisibleTabs = 0 function! s:UpdateListChars(type,value) @@ -14,19 +16,22 @@ function! s:UpdateListChars(type,value) let &l:listchars = join( lc , "," ) endfunction -function! SwitchVisibleTabs() - if s:VisibleTabs == 1 - let s:VisibleTabs = 0 - call s:UpdateListChars( "tab" , " " ) - call s:UpdateListChars( "nbsp" , " " ) - else - let s:VisibleTabs = 1 - call s:UpdateListChars( "tab" , "» " ) - call s:UpdateListChars( "nbsp" , "⚠" ) - endif +function! s:ApplyWhitespaceSettings() + for k in keys(s:Settings) + call s:UpdateListChars( k , s:Settings[k][s:VisibleTabs] ) + endfor endfunction -nnoremap T :call SwitchVisibleTabs() +function! ToggleVisibleWhitespace() + let s:VisibleTabs = 1 - s:VisibleTabs + call s:ApplyWhitespaceSettings() +endfunction + +set list +set listchars="" +call s:ApplyWhitespaceSettings() + +nnoremap ow :call ToggleVisibleWhitespace() augroup TrailingWhitespace autocmd! autocmd InsertEnter * :call UpdateListChars( "trail" , " " )