When writing markdown, a double space at the end of a line indicates a line break. Currently, neither single trailing whitespaces nor double-whitespaces are being highlighted.

Is it possible to have vim highlight trailing whitespace in one colour and markdown breaks (double trailing whitespace as another?). Not essential, but preferably this functionality will be toggleable.


Quick answer:

syntax match Todo "\s$"
syntax match Error "\s\{2}$"
syntax match Visual "\s\{3,}$"

This uses match groups already available from your colorscheme to highlight differently 1,2 or 3+ trailing spaces. You can define your own match groups instead (with more meaningful names for your usage and colored as you please) - see h: match for a quick example:

highlight MarkdownTrailingSpaces ctermbg=green guibg=green
syntax match MarkdownTrailingSpaces "\s\{2}$"

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.