I want to be able to use the gq
key combination in Vim to format the text in my Beamer LaTeX slides.
For example, I'd like gqap
to transform this:
\begin{frame}{Some title}
\begin{itemize}\item first point
\item second point
\item etc. point \end{itemize} \end{frame}
into this:
\begin{frame}{Some title}
\begin{itemize}
\item first point
\item second point
\item etc. point
\end{itemize}
\end{frame}
Specifically, I'd like to observe the following rules:
\item
always begins on a new line\begin
and \end
always begin on a new line\begin{frame}
and \end{frame}
always start in column 1\item
is indented 2 spaces within its environmentThus, my core question relates to how the above could be achieved.
Alternatively, any suggestions on starting points or useful tutorials would be most helpful.
I'd also be interested in any comments about the relative merits of formatexpr
, formatprg
, or internal formatting for performing such formatting.
After a little searching I found this useful answer on Tex.SE to a similar question. It provides a dedicated function for formatting Context source, which could be adapted to LaTeX.
I think I'd prefer something integrated with the built-in gq
functionality in Vim. And the answer still requires a little bit of work to get configured with LaTeX, and I'm not sure what indenting it provides. Anyway, I thought I'd share it in case it was useful to others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With