Mutt: let vim handle syntax highlighting when viewing plain text attachment

0

I use mutt for e-mail and I let vim handle plain text attachments. In my ~/.mailcap I have

text/plain; view %s ; needsterminal

That works fine, but it removes all syntax highlighting. I often receive source code in attachments, and it'd be great to have syntax highlighting. Is there an option that would allow me to preserve it?

I've also tried vim -R -- %s ; needsterminal in ~/.mailcap but the result is the same.

Thanks.

Dominique

Posted 2015-05-12T13:51:55.063

Reputation: 151

Answers

0

Old question, but I thought I'd share my solution; In my mailcaprc I've added text/plain; vim -u <path to my vimrc> - ; needsterminal(the dash is important)

This allows me open the plaintext in vim with my own config by using the m shortcut when opening the plain-text file as an attachment.

Morten

Posted 2015-05-12T13:51:55.063

Reputation: 1

0

Put the following in your ~/.muttrc:

set allow_ansi

That, along with your mailcap rule, worked for me to see a .diff attachment with syntax highlighting.

garyjohn

Posted 2015-05-12T13:51:55.063

Reputation: 29 085

Thanks for the reply but that isn't working for me. Mutt now displays things like gpg: Good signature, etc. in color, as those are probably surrounded by ANSI color codes, but still not joy with syntax highlighting in attachments. – Dominique – 2015-05-12T14:43:12.477

Unfortunately, superuser is not a good forum for troubleshooting. A number of possible issues come to mind, though. Does the view found by mutt have syntax highlighting? (:version) Does view think it's in a color terminal? (:set term? t_Co?) Did view detect the 'filetype'? (:set ft?) Did view choose a syntax file? (:echo b:current_syntax?) When view is displaying an attachment, can it be made to display color at all? (:help colortest.vim) – garyjohn – 2015-05-12T15:21:20.657

When run from the command line, view behaves perfectly and has syntax highlighting. There's only one view on my system. I suspect mutt somehow removes the colors. – Dominique – 2015-05-12T15:34:48.580