You are not logged in.

#1 2017-07-03 18:41:50

marfig
Member
From: Portugal
Registered: 2010-07-30
Posts: 189
Website

[SOLVED] [.vimrc] separate color for trailing spaces symbols

I have set the following `listchars` in .vimrc:

set list listchars=tab:▸\ ,trail:·

On my homemade theme I have set the colors to

highlight SpecialKey     ctermfg=235     ctermbg=none     cterm=none

I understand that `tab` and `trail` share the SpecialKey highlight. But is there a way to separate the two? I'd like to emphasize the trailing spaces symbols but leave the tab symbol nearly invisible. I require the latter since I always work with `noexpandtab`.

Last edited by marfig (2017-07-03 20:01:23)


I probably made this post longer than it should only because I lack the time to make it shorter.
- Paraphrased from Blaise Pascal

Offline

#2 2017-07-03 19:03:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: [SOLVED] [.vimrc] separate color for trailing spaces symbols

Do you want to highlight all spaces, or just trailing spaces?  This really has nothing to do with listchars.  To highlight extra whitespace at the end of a line use:

match ExtraWhitespace /\s\+$/

I have that, and in my theme:

hi ExtraWhitespace    ctermbg=001

I also have the following which essentially prevent this extra whitespace from being highlighted while you are still typing on that line:

autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-07-03 19:55:18

marfig
Member
From: Portugal
Registered: 2010-07-30
Posts: 189
Website

Re: [SOLVED] [.vimrc] separate color for trailing spaces symbols

Most excellent Trilby. Thank you very much.


I probably made this post longer than it should only because I lack the time to make it shorter.
- Paraphrased from Blaise Pascal

Offline

#4 2017-07-03 22:16:54

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 653

Re: [SOLVED] [.vimrc] separate color for trailing spaces symbols

I use this plugin https://github.com/ntpeters/vim-better-whitespace.

Be sure to use Vundle to install and manage your vim plugins if you are not already doing so.

Last edited by bulletmark (2017-07-03 22:17:35)

Offline

#5 2017-07-03 22:26:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: [SOLVED] [.vimrc] separate color for trailing spaces symbols

Er, what?  Several hundred lines of code for a plugin (for which youd then want to add on a plugin manager) just to do what 4 simple lines in your vimrc would accomplish?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2017-07-03 22:39:46

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 653

Re: [SOLVED] [.vimrc] separate color for trailing spaces symbols

Trilby wrote:

Er, what?  Several hundred lines of code for a plugin (for which youd then want to add on a plugin manager) just to do what 4 simple lines in your vimrc would accomplish?

Read the words I linked to. It does a little more than just highlight the trailing whitespace. Vundle is superb and I would suggest anybody interested in better management of vim plugins should be using a manager, or at least be aware of them.

Sorry for making a simple suggestion here!

Offline

#7 2017-07-03 23:10:50

marfig
Member
From: Portugal
Registered: 2010-07-30
Posts: 189
Website

Re: [SOLVED] [.vimrc] separate color for trailing spaces symbols

I prefer pathogen. And that plugin does seem a bit excessive. But thanks for the suggestion anyway.
As a norm I always prefer handwriting my .vimrc/macros/etc instead of installing plugins. Point in fact, I often "steal" plugins code, adapting what bits I want into my own .vim folder. Was stumped on this matter though, until @Tribly taught me I can create my own highlight groups, which is awesome!


I probably made this post longer than it should only because I lack the time to make it shorter.
- Paraphrased from Blaise Pascal

Offline

Board footer

Powered by FluxBB