1

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?

  • Do you want it in inoremap only or okay with any other ways? – SibiCoder Jun 29 '16 at 10:34
  • I am also okay with other ways, I am fairly new to vim so I have always just used inoremap for things like autocompleting braces etc... – Michael Shaulskiy Jun 29 '16 at 10:35
  • 1
    This is probably useful as a learning experience. But if you ever decide to focus on your paper rather than fiddle with Vim, there are several LaTeX plugins around. Some of them are pretty good. There's also the [tex.se] site. – Sato Katsura Jun 29 '16 at 10:39
  • I know that it probably would be more beneficial to read the documentation myself and find the necessary functions myself, however I am currently too busy for that because I have to finish my paper. I know that there are some LaTeX plugins for vim which might be good, however I only need this one feature which is trivial to implement for which a plugin is simply overkill – Michael Shaulskiy Jun 29 '16 at 10:45
  • Others have mentioned LaTeX plugins, which will certainly do the job. You could also look at ultisnips: https://github.com/sirver/ultisnips. You probably won't be able to get the level of interactivity you want with just a map, but ultisnips is designed to make such things easy. – lwassink Jun 29 '16 at 16:39

1 Answers1

0

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.

SibiCoder
  • 1,396
  • 10
  • 21