Vim logo vim online Vim Book Ad

basic Tip #396: Highlighting whitespaces at end of line

 tip karma   Rating 21/14, Viewed by 543 

created:   January 9, 2003 19:04      complexity:   basic
author:   Dubhead      as of Vim:   6.0

Whitespace characters (tabs, spaces, etc) at end of line are rarely meant to be there; they are usually there by accident.  If you don't want them, maybe it pays to highlight them with an alarming color.  (After all, GNU Emacs has it (show-trailing-whitespace), so why not in vim :-) )

Put this in your ~/.vimrc to highlight the whitespace characters at end of line:

highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/

 rate this tip  Life Changing Helpful Unfulfilling 

<<visual marks | mapping for better browsing of :help docs >>

Additional Notes

Anonymous, January 9, 2003 22:13
:set list
<Look at trailing spaces and tabs>
:set nolist
< Now get rid of them>
:%s/\s*$//g
xburgerhout at freeler dot nl, January 9, 2003 23:52
You can also add this line to .vimrc:

let c_space_errors=1

This wil enable trailing whitespace errors in C/C++ files only.
[email protected], January 10, 2003 4:55
I prefer

    set list listchars=tab:>-,trail:.,extends:>

[email protected], January 11, 2003 3:57
You can also use the Cream-based 'showinvisibles' script, which puts bullets for every whitespace at the end of a line
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo