Brady Dean
Brady Dean

Reputation: 3573

Vim autocmd error

I have this script to set variables when loading Python files

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

When I load a Python file I get this error:

Error detected while processing BufRead Auto commands for "*.py":
E518: Unknown option: set

Upvotes: 2

Views: 2420

Answers (3)

Dhruva Sagar
Dhruva Sagar

Reputation: 7307

The following are a couple of ways of achieving what you want :

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

OR

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

Explanation :

In your autocommand you're calling the :set (:h :set) command which is used to set vim options. If you want to set multiple options, you can either call :set with multiple options separated with whitespace or call :set multiple times for each option, separating each :set command with the | (:h :bar).

Tip :

Since your objective is to define certain options specifically for python files, you should either use :autocmd Filetype python ... for this, or better yet create a ftplugin/python/custom.vim file where you can enable these settings using the :setlocal command as opposed to :set to set them only for the current buffer.

Upvotes: 1

Sanjay Chakraborty
Sanjay Chakraborty

Reputation: 1

You can do . instead of *.test and it works for me. (Astrix . Astrix )

Example: au BufNewFile,BufRead . set tabstop=4

Upvotes: 0

Kent
Kent

Reputation: 195059

This should work:

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

or

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

or

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

Upvotes: 5

Related Questions