Highlight email headers with different colors

95 views
Skip to first unread message

Ian N

unread,
Feb 1, 2021, 3:09:15 AM2/1/21
to vim_use
Hello,
I am a new vim+mutt user. I am wondering how to highlight email headers (from, To, CC, Subject, ...) with different colors.
I have done my homework by searching FAQs and more, but I didn't find any answer.
Thank you for your help.
Ian

meine

unread,
Feb 1, 2021, 7:53:01 AM2/1/21
to vim...@googlegroups.com
On Sun, Jan 31, 2021 at 10:02:02PM -0800, Ian N wrote:
> Hello,
> I am a new vim+mutt user. I am wondering how to highlight email headers
> (from, To, CC, Subject, ...) with different colors.

I have the following color settings in my muttrc. Don't know if all
settings are technically correct, but it gives different colors for
different parts of an email. Just put them into your muttrc and see if
it works for you.

//meine


## MUTT COLOURS

# Colours for items in the index
color index brightcyan black ~N
# Hmm, don't like this.
#color index brightgreen black "~N (~x byers.world)|(~x byers.x)|(~x langly.levallois123.axialys.net)|(~x the.earth.li)"
color index brightyellow black ~F
color index black green ~T
color index brightred black ~D
mono index bold ~N
mono index bold ~F
mono index bold ~T
mono index bold ~D

# Highlights inside the body of a message.

# URLs
color body brightgreen black "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
color body brightgreen black "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"

# email addresses
color body brightgreen black "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
#mono body bold "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"

# header
color header green black "^from:"
color header green black "^to:"
color header green black "^cc:"
color header green black "^date:"
color header yellow black "^newsgroups:"
color header yellow black "^reply-to:"
color header brightcyan black "^subject:"
color header red black "^x-spam-rule:"
color header green black "^x-mailer:"
color header yellow black "^message-id:"
color header yellow black "^Organization:"
color header yellow black "^Organisation:"
color header yellow black "^User-Agent:"
color header yellow black "^message-id: .*pine"
color header yellow black "^X-Fnord:"
color header yellow black "^X-WebTV-Stationery:"
color header yellow black "^X-Message-Flag:"
color header yellow black "^X-Spam-Status:"
color header yellow black "^X-SpamProbe:"
color header red black "^X-SpamProbe: SPAM"

# Coloring quoted text - coloring the first 7 levels:
color quoted cyan black
color quoted1 yellow black
color quoted2 red black
color quoted3 green black
color quoted4 cyan black
color quoted5 yellow black
color quoted6 red black
color quoted7 green black

# Default color definitions
#color hdrdefault white green
color signature brightmagenta black
color indicator black cyan
color attachment black green
color error red black
color message white black
color search brightwhite magenta
color status brightyellow blue
color tree brightblue black
color normal white black
color tilde green black
color bold brightyellow black

#color underline magenta black
color markers brightcyan black

# Colour definitions when on a mono screen
mono bold bold
mono underline underline
mono indicator reverse

Christian Brabandt

unread,
Feb 1, 2021, 9:21:29 AM2/1/21
to vim_use

On So, 31 Jan 2021, Ian N wrote:

> Hello,
> I am a new vim+mutt user. I am wondering how to highlight email headers (from, To, CC, Subject, ...) with different colors.
> I have done my homework by searching FAQs and more, but I didn't find any answer.

Do you want to highlight those headers in vim or in mutt?

Best,
Christian
--
Nicht was wir gestern waren, sondern was wir morgen zusammen sein
werden, vereinigt uns zum Staat.
-- José Ortega y Gasset

Ian N

unread,
Feb 1, 2021, 11:35:39 AM2/1/21
to vim...@googlegroups.com
Thank you for the message and the file you sent.

The color file you sent highlights and colors the email headers when viewing the email. This problem I have solved.

Actually, my problem is about highlighting and coloring email headers in vim, when editing the message.

Thank you.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/YBf5pBEHrFzcdA/P%40trackstand.

meine

unread,
Feb 1, 2021, 12:14:45 PM2/1/21
to vim...@googlegroups.com
> Actually, my problem is about highlighting and coloring email headers in
> vim, when *editing the message*.

OK. In my setup I don't see any headers when editing an email -- just a
window with regular Vim. After I quit vim and get back into mutt, I see
the headers, but that is just to, from, subject etc and as/needs no
coloring.

When replying to an email there is only one line above the message that
states 'soandso wrote:', but nothing more.

//meine

Ian

unread,
Feb 1, 2021, 1:23:11 PM2/1/21
to vim_use
I want the headers colored in vim, when I edit/write the message.
I have no problems for coloring the headers when viewing the messages in mutt.



Christian Brabandt

unread,
Feb 2, 2021, 2:40:30 AM2/2/21
to vim_use

On Mo, 01 Feb 2021, Ian wrote:

> I want the headers colored in vim, when I edit/write the message.
> I have no problems for coloring the headers when viewing the messages in mutt.

I am using mutt with vim and :set edit_headers so I see some headers in
each message. If you have your filetype plugin enabled, Vim should
detect a mail from mutt as filetype mail and it colors headers already
using the provided syntax file for the mail filetype (see
$VIMRUNTIME/syntax/mail.vim).

If this is not enough for you, have a look inside this runtime file to
see how to color different headers.


Best,
Christian
--
Ich fürchte mich nicht vor dem, was zu fürchten ist, ich fürchte mich
nur vor der Furcht.
-- Johann Christian Friedrich Hölderlin

Ian N

unread,
Feb 2, 2021, 6:28:52 AM2/2/21
to vim_use
Thank you Christian!
This is exactly what I have already done.

Indeed, the mail.vim file highlights all the mail headers, with the same color (white in this case). 

My question is about how to customize these colors (when writing the mail) - say From: field blue, To: field red, ...
 
I am trying to understand the mail.vim file. It seems it defines the mail header fields all together and colors them with one color.

I am looking for a way to customize the mail header fields 
colors individually. 
Ian

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

Charles Campbell

unread,
Feb 2, 2021, 1:16:35 PM2/2/21
to Ian N
Ian N wrote:
> Thank you Christian!
> This is exactly what I have already done.
>
> Indeed, the mail.vim file highlights all the mail headers, with the
> same color (white in this case).
>
> My question is about how to customize these colors (when writing the
> mail) - say From: field blue, To: field red, ...
> I am trying to understand the mail.vim file. It seems it defines the
> mail header fields all together and colors them with one color.
>
> I am looking for a way to customize the mail header fields
> colors individually.
> Ian
>
You'll need to make a customized syntax/email.vim file. I suggest going
about this one field at a time.

Copy your system's email.vim into $HOME/.vim/syntax/email.vim.
Work with the copy:

Example:
    modify: syn region mailHeader ... remove "|from" from its start pattern
    new syntax: syn region mailHeaderFrom
    new highlighting: hi def mailHeaderFrom (whatever start= cterm=
gui= stuff you want)
    quoted regions: include mailHeaderFrom in mailQuoted[1-6]

Rinse and repeat for whatever fields you want to modify the highlighting
for.

Your version of email.vim will then override the system version, which
you should NOT modify. Future updates to vim could easily wipe your
modified email.vim away should you happen to modify the system version
in place.

Chip Campbell

Ian

unread,
Feb 3, 2021, 1:52:01 AM2/3/21
to vim_use
Definitely this is the way to go. I did try a few things as you suggested, without success.
This requires some more time to understand the file syntax. But I do not have enough time, nor the expertise to 
properly understand the syntax of the file (which seems very condensed). 
I was expecting anyone has already a solution and willing to share.

Thanks for the suggestions anayway.

Christian Brabandt

unread,
Feb 3, 2021, 2:35:13 AM2/3/21
to vim_use

On Di, 02 Feb 2021, Ian wrote:

> Definitely this is the way to go. I did try a few things as you suggested, without success.
> This requires some more time to understand the file syntax. But I do not have enough time, nor the expertise to
> properly understand the syntax of the file (which seems very condensed).
> I was expecting anyone has already a solution and willing to share.
>
> Thanks for the suggestions anayway.

I think the file should be named mail.vim, but otherwise Charles has
mentioned the way to go. FWIW, I never felt the way to color different
headers differently, the default here just colors the Subject line
slightly different than the rest and this just good enough for me, so I
never felt the need to adjust the existing syntax file.

Anyhow, if you want to adjust it, you'll have to read up on syntax
highlighting and regular expressions.

Best,
Christian
Reply all
Reply to author
Forward
0 new messages