I have the following in order to use a different template per language. But I want English to be the default, if I don't specify .en.adoc in the filename. But the *.adoc,*.en.adoc also picks up *.fr.adoc with the result that I get an English and French header in my new *.fr.adoc. How can I avoid this?

autocmd BufNewFile *.adoc,*.en.adoc,~/translate/source/* 0r ~/.local/share/nvim/templates/skeleton.en.adoc

autocmd BufNewFile *.fr.adoc,~/translate/*/target/* 0r ~/.local/share/nvim/templates/skeleton.fr.adoc

1 Answer 1


The reason for this is that both *.adoc and *.fr.adoc match for foo.fr.adoc, so both autocmds are run.

The documentation for autocmd patterns is at :help file-pattern; looking at it, doing a robust "match *.adoc but not fr.adoc" is a bit tricky (though not impossible). Personally, I would opt for just an if:

autocmd BufNewFile *.adoc
            \  if bufname('')[-8:] is# '.fr.adoc'
            \|   :0r ~/.local/share/nvim/templates/skeleton.fr.adoc
            \| else
            \|   :0r ~/.local/share/nvim/templates/skeleton.en.adoc
            \| endif

If you have a lot of skeleton files, you can you look it up in a map let s:skel_files = {'fr.adoc': 'skeleton.fr.adoc'} etc. but for just two, an if should be fine.

  • Thank you! Yes I could see the reason, but just not the proper solution. Much appreciated!
    – Boyd
    May 5, 2020 at 10:05

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.