I am following this guide from realpython.com to fine tune vim for Python development. It suggests the following section in the .vimrc file:

au BufNewFile,BufRead *.py
    \ set tabstop=4
    \ set softtabstop=4
    \ set shiftwidth=4
    \ set textwidth=79
    \ set expandtab
    \ set autoindent
    \ set fileformat=unix

This produces the following error when I open a Python file:

Error detected while processing BufNewFile Auto commands for "*.py":
E518: Unknown option: set 
Press ENTER or type command to continue

As it turns out, the error goes away if the softtabstop instruction is commented out. How should it be set up?


Backslash is a line-continuation in Vim script. Hence your code is interpreted as set tabstop=4 set softtabstop=4 ... and so on. And, obviously, it's a syntax error. Your options are:

  1. Merge options into a single "set" command:

    set tabstop=4 softtabstop=4 shiftwidth=4 ...
  2. Use "bar" to mark command's end:

    set tabstop=4 | set softtabstop=4 | set shiftwidth=4 | ...
  3. Split into several autocommands:

    au BufNewFile,BufRead *.py set tabstop=4
    au BufNewFile,BufRead *.py set softtabstop=4
    au BufNewFile,BufRead *.py set shiftwidth=4

However, in this case it's even better to create a dedicated script for standard "ftplugin" to process. The file name should be ~/.vim/after/ftplugin/python.vim (or $HOME/vimfiles/after/ftplugin/python.vim under Windows). The content is simply a number of "set" commands. You don't have to trap an autocommand yourself as the plugin will do this for you. You have only to enable the plugin with filetype plugin on which is probably switched on anyway.

  • The pipes also produces an error: E749: empty buffer, but the other two solutions are functional. Mar 1 '20 at 11:12

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.