1

I’ve created a new filetype, “usenet,” for Usenet messages. I would like files with this filetype to be highlighted exactly as if they had the “mail” filetype. Is it possible to tell Vim that I want to reuse the existing “mail” syntax definitions for this other filetype?

What I’ve tried

  • I tried writing setlocal syntax=mail in the ftplugin/usenet.vim file but this seemed to be ignored—running :set syntax? in a file with the “usenet” filetype just produced usenet.

  • I also tried copying the mail.vim syntax file from $VIMRUNTIME/syntax into ~/.vim/syntax, renaming it to usenet.vim, and changing the line

    let b:current_syntax = "mail"
    

    to

    let b:current_syntax = "usenet"
    

    This worked, but if a future version of Vim improves the mail.vim file then I would have to go through this process again (and it’s unlikely that I would even notice such a change in the first place). What I want, semantically, is to highlight “usenet” files as if they were “mail” files, which seems like it should be possible.

2

Create a syntax/usenet.vim with the contents:

" Quit when a syntax file was already loaded
if exists("b:current_syntax")
  finish
endif

runtime! syntax/mail.vim
let b:current_syntax = "usenet"

In short, just source the file you want to inherit syntax from. If you want any customizations for usenet, just make them after you've sourced syntax/mail.vim.

3

You can use multiple filetype names separated with .

# in your personal filetype.vim
augroup filetypedetect
  au! BufRead,BufNewFile *.usenet setfiletype mail.usenet
augroup END

All mail filetype plugins and syntax files will be applied before usenet filetype plugins and syntax files. All mail related stuff (abbreviations, snippets, balabalas) should work in usenet.

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.