I want to automate some routine operations when working with LaTeX documents writing, e.g. I often write these lines:

some text and commands here

Where <environment-name> is different environments (e.g. enumerate, description, and many others).

When I start \begin{<environment-name>}, I want to make vim (neovim) automatically add \end{<environment-name>} at the next line and return the cursor back, right after \begin{<environment-name>}. What vim script I can use to automate it?

I already checked this answer but it doesn't work for me, since it's about new command, not auto insertion of text.

  • You can do this with surround.vim (endwise doesnt have it out of the box, but it might be able to handle it)
    – D. Ben Knoble
    Commented Nov 6, 2020 at 13:12
  • 1
    With vimtex, you can close the environment with the insert mode mapping ]]. Commented Nov 6, 2020 at 13:44
  • 2
    ultisnip is what you want.
    – ZhiyuanLck
    Commented Nov 6, 2020 at 14:31


Browse other questions tagged or ask your own question.