heavim/cfg/05-visible-whitespace.vim

39 lines
914 B
VimL
Raw Normal View History

" Trailing spaces and visible tabs
"
" Trailing spaces are visible in normal or visual mode, but hidden in insert
" mode. All whitespace can be made visible using <Leader>ow
2021-12-03 09:20:03 +01:00
let s:VisibleWhitespace = 0
let s:VisibleTrail = 1
2021-12-03 09:20:03 +01:00
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
2021-12-03 09:20:03 +01:00
function! s:ToggleWhitespace()
let s:VisibleWhitespace = 1 - s:VisibleWhitespace
call s:UpdateListChars()
endfunction
2021-12-03 09:20:03 +01:00
function! s:SetVisibleTrail(trail)
let s:VisibleTrail = a:trail
call s:UpdateListChars()
endfunction
set list
2021-12-03 09:20:03 +01:00
call s:UpdateListChars()
nnoremap <silent> <Leader>ow :call <SID>ToggleWhitespace()<cr>
augroup TrailingWhitespace
autocmd!
2021-12-03 09:20:03 +01:00
autocmd InsertEnter * :call <SID>SetVisibleTrail(0)
autocmd InsertLeave * :call <SID>SetVisibleTrail(1)
augroup END