Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use vim's source code formatting features (the = key will format your selection and pressing gg=G will format the entire source code).

However, it seems to not format correctly when it encounters line breaks (\\). It will always indent the next paragraph when it sees those line breaks.

Is there any way to fix this?

share|improve this question
    
what does your latex.vim look like? (If you are using one) Do you have any other Source formats set? Can you replicate with them? Or are you using the vimrc method. –  Dan M. Jan 7 '11 at 18:37
    
i'm just using whatever default latex.vim is included with vim. I don't see anything related to this in my .vimrc file. It's a pretty plain install. if you just open a .tex file and type something like "asdf \\ sdf \\ dfg" on 3 lines, it will indent the lines incorrectly. –  vonhogen Jan 7 '11 at 18:45

1 Answer 1

It seems to be a bug in Vim. [Not true. See EDIT below.--garyjohn] If you start Vim like this,

vim -N -u NONE

so that no configuration files or plugins are loaded, and try your example, those lines are still indented as you describe. Under those conditions, I don't think Vim should be doing any indentation since all the indentation options (e.g., 'autoindent', 'cindent') are off. Nevertheless, the following command seems to fix this problem:

:set cinoptions=+0

That tells Vim not to indent continuation lines. That setting shouldn't have any effect if 'cindent' is not set, but it seems to anyway.

I was using Vim 7.2.148 on Linux.

EDIT:

This is not a bug in Vim. According to Vim's author, this is not a bug but the desired behavior. He says that the = indenting function should do something by default, so it obeys the C indenting settings. Setting 'cindent' merely enables automatic indentation, e.g., when you hit Enter. (That the actual indentation is two 'shiftwidth's rather than one as documented is another issue.)

Since what you really want is some sort of indentation for LaTeX code, setting 'cinoptions' to "+0" is not really a solution either. Vim doesn't come with any indenting rules for LaTeX, so you might want to install one of the LaTeX plugins. I use VIM-LaTeX-suite, but you can find others by going to Vim's Advanced search page and searching scripts for "latex".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.