Skip to content

Instantly share code, notes, and snippets.

@tommcdo
Last active December 30, 2015 12:19
Show Gist options
  • Save tommcdo/7828217 to your computer and use it in GitHub Desktop.
Save tommcdo/7828217 to your computer and use it in GitHub Desktop.
Highlight trailing whitespace in files via a toggle.
function! TrailingWhitespaceToggle(...)
let hlgroup = a:0 ? a:0 : 'Search'
if !exists('s:trailing_whitespace_match')
let s:trailing_whitespace_match = matchadd(hlgroup, '\s\+$')
echo 'Trailing whitespace on'
else
call matchdelete(s:trailing_whitespace_match)
unlet s:trailing_whitespace_match
echo 'Trailing whitespace off'
endif
endfunction
nnoremap <F9> :<C-u>call TrailingWhitespaceToggle()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment