Reputation: 3542
Is there an easy way to display whitespace characters such as space and tab in gvim? Something like what is implemented in Gedit, Geany, Komodo, and other GUI editors where (when the option is turned on) spaces show as a muted or greyed-out '.' and tabs as '-->'.
Upvotes: 38
Views: 34879
Reputation: 1
This works well for me:
"trailing white space detection
highlight WhitespaceEOL ctermbg=yellow guibg=yellow
match WhitespaceEOL /\s\+$/
Upvotes: 0
Reputation: 18488
Here are some of my settings pertaining whitespace.
Use F11
to toggle between displaying whitespace characters or not:
noremap <F11> :set list!<CR>
How to show whitespace characters when list
is set:
set listchars=eol:$,tab:>-,trail:.,extends:>,precedes:<,nbsp:_
Highlight special characters in yellow:
highlight SpecialKey term=standout ctermbg=yellow guibg=yellow
Highlight redundant spaces (spaces at the end of the line, spaces before or after tabs):
highlight RedundantSpaces term=standout ctermbg=Grey guibg=#ffddcc
call matchadd('RedundantSpaces', '\(\s\+$\| \+\ze\t\|\t\zs \+\)\(\%#\)\@!')
Hope these help!
Upvotes: 7
Reputation: 11395
You can use any characters you wish if you enable Unicode first
set encoding=utf-8
One line I use (put in ~/.vimrc
):
set list listchars=tab:→\ ,trail:·
Learn more about this setting at http://vim.wikia.com/wiki/Highlight_unwanted_spaces
The color of these characters is controlled by your color scheme.
Upvotes: 30
Reputation: 20591
Check out listchars
and list
options in Vim. An example use of this feature:
" part of ~/.vimrc
" highlight tabs and trailing spaces
set listchars=tab:>-,trail:-
set list
Upvotes: 39