1

Can anyone explain to me why when writing python code, vim is auto indenting when entering carriage return after function call ie. f.write(name, r)

Before writing(:w) file

import bs4 as bs
import urllib.request
sauce = urllib.request.urlopen('http://www.google.com').read()

soup = bs.BeautifulSoup(sauce, 'lxml')

path = "~/Workspace/scraping/"
filename = "demo.html"
fullname = path + filename

f=open(fullname, 'w')
f.write(soup)
    print(f) #why auto indenting here?

After writing (:w) file

import bs4 as bs
import urllib.request
sauce = urllib.request.urlopen('http://www.google.com').read()

soup = bs.BeautifulSoup(sauce, 'lxml')

path = "~/Workspace/scraping/"
filename = "demo.html"
fullname = path + filename

    f=open(fullname, 'w') #???
    f.write(soup)         #???
print(f)                  #???

.vimrc file setting for python file

autocmd BufNewFile, BufRead *.py 
     \ set tabstop=4
     \ set softtabstop=4
     \ set shiftwidth=4
     \ set textwidth=80
autocmd BufWritePre *.py  :normal gg=G

"indent settings for all files
set cindent
set autoindent

Machine Details

VIM

Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:44:48)
Included patches: 1-1689
Extra patches: 8.0.0056

Features:

-python
+python3

Python

Python 2.7.12
Python 3.5.2

Any input at all would be greatly appreciated. Cheers!

| improve this question | | | | |
  • Could you paste that screenshot as text? Not only is that easier to read, it would also mean people don't have to manually type in six lines of text to reproduce your issue ;-) – Martin Tournoij May 4 '17 at 17:30
  • @Carpetsmoker Thanks for pointing that out. I continued messing with it and my have further focused in on the condition I'm trying to figure out. I've modified the question and added some more before and after code snippets. – TekkSparrow May 4 '17 at 18:31
1

Turns out trading autoindent for smartindent seems to get everything working as it should.

  1. turned autoindent off :set noautoindent
  2. turned on smart indent :set smartindent
| improve this answer | | | | |

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.