3

If I open a given mail file in ~/maildir-sent/ then file has no syntax highlighting. Vi has default highlighting for mail files, and I can turn this on manually with

:set ft=mail This doesn't occur by default because mail files there have the awkward name structure 1339174749.7162_2.tm24-s00418:2,S

How do I make mail files highlighting occur by default? I.E. I presume this default reads like "all files that are not matched by another syntax highlight definition"

1 Answer 1

7

Use an autocmd in your .vimrc:

autocmd BufRead ~/maildir-sent/* setlocal ft=mail

See :help autcmd for more information.

6
  • If there were, say, a .rb file in that directory - would it remain highlighted as a Ruby file? Jul 23, 2012 at 16:11
  • Generally, no, but it depends on your setup. It's better in autocommand if you can be specific about file extensions if you'll have lots of different filetypes requiring specific highlighting in the targeted directory. Since this is a mail directory it seems like you needn't be very specific. You can solve such issues with additional autocommands for the directory and specific extensions
    – pb2q
    Jul 23, 2012 at 16:14
  • So far this doesn't work for me with vim 7.3, even using au instead of autocommand. You've set this ont he right path, but I don't have the solution quite yet. Jul 23, 2012 at 20:43
  • @NewAlexandria edited a mistake in the answer, I'd typed BufEnter rather than BufRead
    – pb2q
    Jul 23, 2012 at 20:52
  • 1
    @NewAlexandria bah definitely off today: it's autocmd not autocommand. sorry. You should've been seeing Not an editor command: autocommand ... when starting up with that line
    – pb2q
    Jul 23, 2012 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.