Formatting Latex in vim - issues with line breaks

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?

vonhogen

Posted 2011-01-07T18:27:06.833

Reputation: 1 949

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. – 2011-01-07T18:37:14.780

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 – 2011-01-07T18:45:20.233

Answers

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

garyjohn

Posted 2011-01-07T18:27:06.833

Reputation: 29 085