vimlatexcopy-pasteenvironmentyank

Vim: yank an entire environment of Tex file


I am using vim with latex-suite to edit my document and sometimes need to copy an entire environment (from \begin{...} to \end{...}). For example, I want to copy this part

\begin{align*}
  \sigma &\rightarrow A | B | C | ABC \\
  A &\rightarrow a | \varepsilon \\
  B &\rightarrow b | \varepsilon \\
  C &\rightarrow c | \varepsilon
\end{align*}

Whenever I need to do that, I have to move to the begin tags, count the number of line and enter the yank command (6yy in the case of the above example).

My question is:

  1. Is there any faster way to do this job which is similar to yank an entire tag in html or xml file (yit, yat)?
  2. If there isn't, could you please show me how can I create my own command to do this in vim?

Solution

  • I would advise you to use vim-textobj-latex plugin which gives you some new text object. Specifically the ae and ie text objects for "an environment" and "inner environment".

    Note: vim-textobj-latex plugin relies on vim-textobj-user