When I am writting a Latex document I generally like to keep an 80 column line width to keep things easy to read. However I don't like to use text wrapping because it can get in the way of typing equations.
Normally I will type a paragraph without caring how long the lines are, and eventually they gradually get longer, and longer, to the point where if I vsplit
two documents the lines run off the end. So I will set textwitdth=80
and highlight an offending section in visual mode, and then use gq
to format the selected text. However this is a bit more of a process than I have come accustomed to using vim I prefer to do things with only a few key strokes, or have it automatically done based on the file type.
I am looking for a way to either:
- script the application of a particular format (predetermined) to a selection of text
- Apply conditional formatting to a file-type based on some of the same identifiers used to conditionally highlight syntax
For those unfamiliar with latex:
A regular text section is by and large free of any syntax. When you
begin an equation like this,
\begin{equation}
\hat{H}\Psi = E\Psi
\end{equation}
I wouldn't want the lines inside to be wrapped automatically.
So there is a clear way of identifying math environments ie\begin..\end
and Vim's ft plugin recognizes this for syntax highlighting. Can you apply conditional formatting in a similar way?
This (latex) is an example I am working with right now, but for example in general programming I would really like it if multi line comments could be wrapped without automatically wrapping regular code.