At the moment, I'm trying to highlight the spaces/tabs used for indentation and the end-of-line with special characters.

Although I prefer tabs over spaces I also need the spaces highlighted in order to easily differentiate spaces against tabs if there is an indentation mistake I made or see the spaces when I'm coding in Haskell.

Based on the above, the related configuration in my .vimrc is:

set tabstop=2▸▸ ▸ ▸ ▸ ▸ " number of visual spaces per TAB¬
set shiftwidth=2▸ ▸ ▸ ▸ " number of space characters inserted for indentation¬
 set softtabstop=2▸▸ ▸ ▸ " number of spaces in a tab while editing¬
set noexpandtab▸▸ ▸ ▸ ▸ " tabs are tabs, not spaces¬
set autoindent¬
set list listchars=tab:▸\ ,eol:¬,precedes:• " show invisibles¬

As can be seen, the listchars options work fine for the tabs and end-of-line but I can't make the preceding space before a line get marked with the character I've defined(I've intentionally left out a preceding space in the above config. In the actual file, a preceding space is just a space but not the character I've defined it to be).

I went through the documentation and tried various options but couldn't get my head around it.

Am I missing something or is there a configuration conflict that I'm not aware of since I'm preferring tabs over spaces?


The precedes suboption of the listchars option, is used to indicate, if the line has some content before the first visible character. It has nothing to do with showing preceding spaces or such.

If you want to highlight spaces in addition, you can add the spaces key to the listchars option. However, this will mark all spaces in the current window, which might be a bit too much.

If you want to show preceeding spaces, you can instead use concealing using the match() functions. Something like this could be working for your:

 call matchadd('Conceal', '\(^ *\)\@<= ', 0, -1, {'conceal': '-'})
 set conceallevel=2 concealcursor=nv

Note, this is local per window, so you might need to add some autocommands to have this apply to every window you open (or every file you open).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.