6

I have what I thought was a pretty simple setup in my neovim init.vim file. Basically all I wanted it to do was configure the tab settings when opening an HTML file. My configuration is:

au BufNewFile,BufRead *.html, *.css
    \ set tabstop=2
    \ softtabstop=2
    \ shiftwidth=2

When I open an HTML file I get the following error message:

Error detected while processing BufReadPost Auto commands for "*.html":
E20: Mark not set

I don't understand why this is throwing an error. I have a similar line in my config file for *.py yet I receive no errors when opening Python files.

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
Ron Obvious
  • 63
  • 1
  • 3

2 Answers2

10

You need to use | to run multiple commands:

set tabstop=2 | softtabstop=2

It doesn't matter if you're using multiple lines, you still need to use the |:

au BufNewFile,BufRead *.html, *.css
    \  set tabstop=2
    \| set softtabstop=2
    \| set shiftwidth=2

You can set multiple values with set, so the same can be expressed as:

au BufNewFile,BufRead *.html, *.css
    \ set tabstop=2 softtabstop=2 shiftwidth=2

You probably want to use setlocal, rather than set. set will affect all buffers, so your autocommand will also change the settings for a .js buffer for example. setlocal will only affect the current buffer.

au BufNewFile,BufRead *.html, *.css
    \ setlocal tabstop=2 softtabstop=2 shiftwidth=2

Using the Filetype autocommand is probably better too. There may be other cases where the html or css syntax is loaded (for example my setting it manually):

au FileType html,css
    \ setlocal tabstop=2 softtabstop=2 shiftwidth=2

Personally, I always want these three settings to have the same value, if you use shiftwidth=0 it will use the value of the tabstop setting, and softtabstop=-1 will make that use the shiftwidth setting, so then you can use:

set shiftwidth=0    " Use tabstop
set softtabstop=-1  " Use shiftwidth

au FileType html,css setlocal tabstop=2
Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
4

I have similar issue. The culprit is the space between patterns, like

*.html, and *.css

Removing the space should fix it. Good luck.

Reference > https://stackoverflow.com/questions/45416839/error-detected-while-processing-bufread-auto-commands-for-py

j3ffyang
  • 141
  • 3