none
none

Reputation: 12137

default automatic line break for python files in vim

When I edit a python file in vim, formatoptions is set to tcq for some reason making it automatically break long lines in code which sometimes may break the code as well. This is in contrary to other code filetypes such as c or java where automatic line breaks only occur in comments. I can disable this by removing t from formatoptions but I was wondering why the default behavior is set to this for python files?

Also where are formatoptions are set for different filetypes?

Upvotes: 0

Views: 2060

Answers (1)

romainl
romainl

Reputation: 196886

Use :verbose set <option> to see where it's set.

If it's in a default file: don't touch it, just set the correct value in your ~/.vimrc.

If it's in some third party script: see why it's set that way, try the desired value, see if it breaks anything.

edit

I'm dumb as a rock. Do you hear me? Dumb. As. A. Rock.

tcq is simply the default value of formatoptions. I guess ~/.vimrc is a (non-intuitive) way for Vim to say that.

The default Python ftplugin doesn't set it to another value so you'll have to do that yourself. Here is what I have in ~/.vim/after/ftplugin/python.vim:

setlocal tabstop=4
setlocal shiftwidth=4
setlocal softtabstop=4
setlocal smartindent
setlocal formatoptions=croql
setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class
setlocal omnifunc=pythoncomplete#Complete

Upvotes: 1

Related Questions