2

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?

2
  • 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.
    – user61724
    Commented Jan 7, 2011 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
    Commented Jan 7, 2011 at 18:45

1 Answer 1

2

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".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .