Question

Whenever I want to use line continuation in my python script using macVim, I receive the following format:

a = one,\
        two,\
        three

instead of:

a = one,\
    two,\
    three

I've rifled through help, and was unable to locate what exactly is causing macVim to append an extra tab upon using line continuation.

Note: I currently have the following in my .vimrc file:

set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4
Was it helpful?

Solution 2

Your settings are almost fine. In Python code, the tab settings should always be

:set tabstop=8 shiftwidth=4 softtabstop=4 expandtab

These settings honour the recommendations in the "Style guide for Python code" known as PEP 8 and are universally followed in Python code. Stick to these settings, or even better, set up an autocommand that sets them automatically. In your vimrc:

autocmd FileType python setlocal ts=8 sw=4 sts=4 et

Now on to your problem: This is caused by the default indentation rules in Vim's indent script for Python. Fortunately, these rules can be customised. In your case you just need to put the following line in your vimrc.

let g:pyindent_continue = '&shiftwidth'

(In newer versions of Vim, use 'shiftwidth()' instead of '&shiftwidth'.)

For more information, look up :h ft-python-indent.

OTHER TIPS

You have your tabs set to 4 and not 2

Make sure that you have

filetype plugin indent on 

You can also use something as followed in your .vimrc as a oneliner for defaults instead of adding them on separate lines

Use 2 instead of 4

set ts=2 sts=2 sw=2 noexpandtab
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top