2015-03-02 17:58:40 +01:00
|
|
|
" Trailing spaces and visible tabs
|
|
|
|
"
|
|
|
|
" Trailing spaces are visible in normal or visual mode, but hidden in insert
|
2020-12-07 15:04:39 +01:00
|
|
|
" mode. All whitespace can be made visible using <Leader>ow
|
2015-03-02 17:58:40 +01:00
|
|
|
|
2020-12-07 15:04:39 +01:00
|
|
|
let s:Settings = {
|
|
|
|
\ 'tab' : [ " " , "» " ] ,
|
|
|
|
\ 'nbsp' : [ " " , "⚠" ] ,
|
|
|
|
\ 'space' : [ " " , "·" ] ,
|
|
|
|
\ 'eol' : [ " " , "¶" ] ,
|
|
|
|
\ }
|
2015-03-02 17:58:40 +01:00
|
|
|
let s:VisibleTabs = 0
|
|
|
|
|
|
|
|
function! s:UpdateListChars(type,value)
|
|
|
|
let lc = filter( split( &l:listchars , "," ) , "v:val !~ '^" . a:type . ":'" ) + [ a:type . ":" . a:value ]
|
|
|
|
let &l:listchars = join( lc , "," )
|
|
|
|
endfunction
|
|
|
|
|
2020-12-07 15:04:39 +01:00
|
|
|
function! s:ApplyWhitespaceSettings()
|
|
|
|
for k in keys(s:Settings)
|
|
|
|
call s:UpdateListChars( k , s:Settings[k][s:VisibleTabs] )
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! <SID>ToggleVisibleWhitespace()
|
|
|
|
let s:VisibleTabs = 1 - s:VisibleTabs
|
|
|
|
call s:ApplyWhitespaceSettings()
|
2015-03-02 17:58:40 +01:00
|
|
|
endfunction
|
|
|
|
|
2020-12-07 15:04:39 +01:00
|
|
|
set list
|
|
|
|
set listchars=""
|
|
|
|
call s:ApplyWhitespaceSettings()
|
|
|
|
|
|
|
|
nnoremap <silent> <Leader>ow :call <SID>ToggleVisibleWhitespace()<cr>
|
2015-03-02 17:58:40 +01:00
|
|
|
augroup TrailingWhitespace
|
|
|
|
autocmd!
|
|
|
|
autocmd InsertEnter * :call <SID>UpdateListChars( "trail" , " " )
|
|
|
|
autocmd InsertLeave * :call <SID>UpdateListChars( "trail" , "•" )
|
|
|
|
augroup END
|