Fixed visible whitespace handling
This commit is contained in:
parent
cceb4b3833
commit
79d2a20b1f
1 changed files with 21 additions and 22 deletions
|
@ -3,37 +3,36 @@
|
||||||
" Trailing spaces are visible in normal or visual mode, but hidden in insert
|
" Trailing spaces are visible in normal or visual mode, but hidden in insert
|
||||||
" mode. All whitespace can be made visible using <Leader>ow
|
" mode. All whitespace can be made visible using <Leader>ow
|
||||||
|
|
||||||
let s:Settings = {
|
let s:VisibleWhitespace = 0
|
||||||
\ 'tab' : [ " " , "» " ] ,
|
let s:VisibleTrail = 1
|
||||||
\ 'nbsp' : [ " " , "⚠" ] ,
|
|
||||||
\ 'space' : [ " " , "·" ] ,
|
|
||||||
\ 'eol' : [ " " , "¶" ] ,
|
|
||||||
\ }
|
|
||||||
let s:VisibleTabs = 0
|
|
||||||
|
|
||||||
function! s:UpdateListChars(type,value)
|
function! s:UpdateListChars()
|
||||||
let lc = filter( split( &l:listchars , "," ) , "v:val !~ '^" . a:type . ":'" ) + [ a:type . ":" . a:value ]
|
if s:VisibleWhitespace
|
||||||
let &l:listchars = join( lc , "," )
|
set listchars=tab:»\ ,nbsp:⚠,space:·,eol:¶
|
||||||
|
else
|
||||||
|
set listchars=tab:\ \ ,
|
||||||
|
endif
|
||||||
|
if s:VisibleTrail
|
||||||
|
set listchars+=trail:•
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ApplyWhitespaceSettings()
|
function! s:ToggleWhitespace()
|
||||||
for k in keys(s:Settings)
|
let s:VisibleWhitespace = 1 - s:VisibleWhitespace
|
||||||
call s:UpdateListChars( k , s:Settings[k][s:VisibleTabs] )
|
call s:UpdateListChars()
|
||||||
endfor
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! <SID>ToggleVisibleWhitespace()
|
function! s:SetVisibleTrail(trail)
|
||||||
let s:VisibleTabs = 1 - s:VisibleTabs
|
let s:VisibleTrail = a:trail
|
||||||
call s:ApplyWhitespaceSettings()
|
call s:UpdateListChars()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
set list
|
set list
|
||||||
set listchars=""
|
call s:UpdateListChars()
|
||||||
call s:ApplyWhitespaceSettings()
|
nnoremap <silent> <Leader>ow :call <SID>ToggleWhitespace()<cr>
|
||||||
|
|
||||||
nnoremap <silent> <Leader>ow :call <SID>ToggleVisibleWhitespace()<cr>
|
|
||||||
augroup TrailingWhitespace
|
augroup TrailingWhitespace
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd InsertEnter * :call <SID>UpdateListChars( "trail" , " " )
|
autocmd InsertEnter * :call <SID>SetVisibleTrail(0)
|
||||||
autocmd InsertLeave * :call <SID>UpdateListChars( "trail" , "•" )
|
autocmd InsertLeave * :call <SID>SetVisibleTrail(1)
|
||||||
augroup END
|
augroup END
|
||||||
|
|
Loading…
Reference in a new issue