I'm a tabs kind of guy, so I highlight leading and trailing white spaces with the following commands in my .vimrc:

highlight whiteSpace_trailing ctermbg=red guibg=red
highlight whiteSpace_leading  ctermbg=red guibg=red
match  whiteSpace_trailing /\s\+$/
2match whiteSpace_leading /^ \+/

This works fine when I have only one window open. However, when opening a second window with visual splits for example, these specs are not taken into account. Any idea why and how to fix it?

  • This isn't a direct answer to your question, but have you looked at the listchars option? It can highlight whitespace for you. I have the following in my vimrc: set list listchars=tab:>-,trail:·. This will make it show tabs as >--- and trailing spaces as ·. – Tumbler41 Dec 6 '16 at 19:49
  • @Tumbler41 It's not the first time I see someone mention it but first time I actually try it. It does seems to work in visual splits as well. This may be an alternative as I find the red highlighting a bit too agressive sometimes. I found another post on SE that states that the combination of list and listchars only works on trailing white space but not leading spaces – solalito Dec 6 '16 at 20:13
  • You can also see spaces if you add space:· to the list (separated by a comma of course). Of course this is all spaces, not leading spaces. – Tumbler41 Dec 6 '16 at 20:30
  • matches are window local. So you need to put this into a WinEnter or BufWinEnter autocommand. – Christian Brabandt Dec 7 '16 at 18:40

Your Answer

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

Browse other questions tagged or ask your own question.