# Shortcut for inserting matching \end{something} in VIM

I remember some time ago I always used a shortcut in VIM that allowed me to type this (<X> is indication of the location of the cursor):

... rest of document ...

\begin{<ENVIRONMENT>}
some text
more text
<X>

... document continues ....


and then I would key in some shortcut at the location of <X> and the matching \end{<ENVIRONMENT>} would be inserted:

... rest of document ...

\begin{<ENVIRONMENT>}
some text
more text
\end{<ENVIRONMENT>}

... document continues ....


Here, of course, <ENVIRONMENT> can be anything, like align or itemize.

I know about VIM's <C-x> + <C-p>, <C-x + <C-n> and <C-x> + <C-o>. The last one works very well for closing HTML tags, but it doesn't work in LaTeX.

I forgot what it was and I hope someone here knows it. It might have been a plugin but I don't think so. If anyone can tell me what it is, I will be forever grateful.

EDIT: Of course I am using LaTeX-Suite (or vim-latex, wish they'd stick to a name).

-
I'm not referring to that, but nice to know, it's basically as useful as what I'm looking for, thank you! – pancake Jul 4 '12 at 19:04
Perhaps you are thinking of the closeb script. – Aditya Jul 4 '12 at 22:17
Tested the closeb script, works very well. – Rmano Feb 4 '14 at 0:22

Something that is pretty much as useful is to type nameofenvironment then F5 which gives

\begin{nameofenvironment}

\end{nameofenvironment}<++>


and puts the cursor in the body of the environment. You can leave the environment easily by pressing CTRL J

-

When using VimTeX, you can type ]] in insert mode to close the current environment.

-

You search for the closeb plugin. It does exactly what you describe.

If you enable it and press Ctrl+_ in insert mode, it closes the current environment.

-