Error detected while processing BufRead Auto commands for “*.py”

It’s hard to notice (I had to look twice), but the problem is the spaces between the patterns in the :autocmd definition:

The syntax is

:au[tocmd] [group] {event} {pat} [nested] {cmd}

:help {pat} shows that there must not be whitespace between individual patterns.

Example

:au BufNewFile,BufRead *.py, *.php, *.rb, *.html, *.js, *.ts, *.md echomsg 'test'

:au BufRead *.py
--- Auto-Commands ---
filetypedetect  BufRead
    *.py      setf python
BufRead
    *.py      *.php, *.rb, *.html, *.js, *.ts, *.md echomsg 'test'

As you can see, Vim only recognizes the first pattern, and takes all following as (Ex) commands!

The :* command executes the contents of a register (probably rubbish), and that causes the E20 error you’ve seen (probably because there’s the ' character in the register).

Fix

Drop the whitespace. As I’ve already commented, you can also skip repeating the :set commands for each option.

:au BufNewFile,BufRead *.py,*.php,*.rb,*.html,*.js,*.ts,*.md ...

Leave a Comment

tech