Search code examples
vimlatexviml

Vim LaTeX \begin autocomplete


I am currently writing a mathematical paper using LaTeX and I am pretty content with vim, however, the only thing I miss from TeXMaker are the automatically generated \begin{}\end{} blocks. So I am currently wondering how someone might implement such a functionality using the inoremap command in the same way as TeXMaker, so that after you, for example, type \begin it extends it to \begin{<env>} \end{<env>} and places the cursor between the braces and after you replace <env> with an environment it replaces it both in the \begin{} and in the end{} command.

Is this even possible with just vim script?


Solution

  • This command will take the word under cursor and make a block like what you wanted

         :noremap \b cw\begin{<C-R>"}<CR>\end{<C-R>"}
    

    Keep the cursor at start of the word and press \b in normal mode to get the desired output.