Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using vim's `gqap' sometimes indents unusually

Tags:

vim

latex

For the life of me, I cannot figure out the cause of this: when writing in LaTeX documents, I like to keep my line width to maximum of 80 characters. As such, I will execute the vim command gqap and vim will automatically re-wordwrap the paragraph I am writing.

For example, it will cause a long line to become many shorter ones:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem. Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla nec, vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula aliquam tincidunt. Proin condimentum rutrum lacinia.

becomes:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra
nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem.
Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in
consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla nec,
vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula aliquam
tincidunt. Proin condimentum rutrum lacini

But, for some paragraphs, it will start adding unusual indentions towards the end of the paragraph:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra
nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem.
Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in
     consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla,
     vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula
     tincidunt. Proin condimentum rutrum lacini

Why does vim do this? I have yet to figure out the pattern. How can I make it format paragraphs "the correct way"?

like image 816
carl Avatar asked Nov 15 '09 06:11

carl


2 Answers

Yes, vim's 'smartindent' is not well named. I had trouble with this for a while before I figured out what was wrong. For others, if you notice strange indenting behavior after lines starting with "if" or "for", unset smartindent. You will come across this a lot if you start using vim as a word processor.

From the vim help file, 'smartindent' will indent after a line starting with a keyword from 'cinwords', which is "if,else,while,do,for,switch", by default.

like image 145
yamad Avatar answered Sep 22 '22 04:09

yamad


The problem was that I had "smartindent" enabled. Disabling this for LaTeX documents solved it:

au BufEnter *.tex set nosmartindent
like image 32
carl Avatar answered Sep 19 '22 04:09

carl