0

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?

2
  • Try this - stackoverflow.com/questions/1290285/… ? Commented Nov 4, 2012 at 17:03
  • @CalvinCheng close but not the answer I was looking for. I don't have to set anything with my c or java files even though I have tw and wm set. it sounds like a bug to me or I just don't see the point.. Commented Nov 4, 2012 at 17:12

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

7 Comments

it says ~/.vimrc but I don't have anything set in it
so for other file types such as c, it gives me $VIMRUNTIME/ftplugin/c.vim but for python it says .~/.vimrc which is not true, or at least it doesn't give me anything useful because it's not in that file.
Vim wouldn't point to that file if the option was not set there. You should post your ~/.vimrc.
It's not there. Do you have non-commited/pushed changes? Is your ~/.vimrc a symlink to the vimrc in your repo? I see you have activated modelines, do the python files have modelines?
(1)I don't have non-commited/pushed changes. (2)yes, ~/.vimrc is a symlink to vimrc. (3)It happens with python files without modelines. (4)Can you try it on your vim to see if you have the same problem? I highly doubt this is related to my vim configuration.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.