Quantcast

Strange auto indent behavior after function calls and variable assignments

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Strange auto indent behavior after function calls and variable assignments

Jacques Troussard
Can anyone explain to me why when writing python code, vim is auto indenting after this variable assignment?

.vimrc file setting for python file
autocmd BufNewFile, BufRead *.py                                                
     \ set tabstop=4                                                            
     \ set softtabstop=4                                                        
     \ set shiftwidth=4                                                          
     \ set textwidth=80

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

Screenshot from 2017-05-04 11-58-24.png (74K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange auto indent behavior after function calls and variable assignments

Gary Johnson-4
On 2017-05-04, Jacques Troussard wrote:
> Can anyone explain to me why when writing python code, vim is auto
> indenting after this variable assignment?
>
> .vimrc file setting for python file
> autocmd BufNewFile, BufRead *.py
>      \ set tabstop=4
>      \ set softtabstop=4
>      \ set shiftwidth=4
>      \ set textwidth=80

I don't know why Vim is autoindenting, unless you have 'autoindent'
set somewhere or you have filetype indenting enabled.

But, that autocmd is not going to work, if that's what it really is
and the above is not just a transcription error.

To start with, spaces are not allowed within the list of events. The
two events should be given as

    BufNewFile,BufRead

You have told Vim to look for a BufNewFile event for a file named
BufRead.

Secondly, when you use \ to continue Vim statements, all the lines
in the statements are concatenated together as though they were on
one line.  Vim sees your autocmd as the single line:

    autocmd BufNewFile, BufRead *.py set tabstop=4 set softtabstop=4 set shiftwidth=4 set textwidth=80

There are two ways to fix that.  One is to put the command
separator | between the set commands, as:

    autocmd BufNewFile,BufRead *.py
         \   set tabstop=4
         \ | set softtabstop=4
         \ | set shiftwidth=4
         \ | set textwidth=80

The other is to put all those settings into one set command, as:

    autocmd BufNewFile,BufRead *.py
         \ set tabstop=4
         \     softtabstop=4
         \     shiftwidth=4
         \     textwidth=80

See also:

    :help line-continuation
    :help :bar

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...