I've got a template for vimwiki diary entries that's invoked via this autocommand:

autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py

But I want to be able to create other *mkd files in that directory without that template being invoked.

The times I want the diary template to be invoked are when new file name is like 2020-09-21.mkd. So I'd like to be able to change the autocmd to something like...

autocmd BufNewFile ~/Documents/wiki/diary/[0-9]{4}-[0-9]{2}-[0-9]{2}.mkd :silent 0r !vimwiki-diary-template.py

But that doesn't work.

And I don't see anything in :help autocmd-patterns about integers/digits/numerals/numbers.

If I do ls ~/Documents/wiki/diary | grep -E '[0-9]{4}-[0-9]{2}-[0-9]{2}.mkd' that shows the files I want this template to be applied to. But I don't know how to utilize that regex in the vim autocmd. Can this be done?

1 Answer 1


The patterns used in auto-commands are different from normal regexes. In :help file-pattern you'll see that you actually need \\\{m,n\} to specify repetition of an item.

So, in your case, what you actually want is:

autocmd BufNewFile ~/Documents/wiki/diary/[0-9]\\\{4\}-[0-9]\\\{2\}-[0-9]\\\{2\}.mkd :silent 0r !vimwiki-diary-template.py

Note that in some of those cases, it might be easier to just repeat the [0-9] a few times, rather than to deal with this somewhat awkward syntax.

  • 1
    I saw that line in the :help but didn't know what it meant. When I saw the m,n part it made me think of a range rather than quantity.
    – alec
    Sep 21, 2020 at 23:35
  • 1
    @alec autocommand patterns have more in common with shell globs than regex
    – D. Ben Knoble
    Sep 22, 2020 at 0:55

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.