this post was submitted on 11 Mar 2024
12 points (92.9% liked)

Neovim

2185 readers
2 users here now

founded 1 year ago
MODERATORS
12
Help with snippets? (lemmy.sdf.org)
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/[email protected]
 

My goal is to automatically close the environment while editing a tex file. There was an issue for vimtex asking for basically what I want to achieve. They achieve it using snippets as mentioned there.

The problem is, I have no idea how to set it up. I've never used snippets in nvim. I have vim-vsnip and cmp-vsnip installed as it was needed for another plugin to work. Is it possible to implement this using those?

It can be noted that in vimtex, an environment can be closed by typing ]] which is a mapping of vimtex-delim-close. I basically want to emulate the behavior in VS Code using LaTeX Workshop. It auto-closes the environment, adds an indented line in the middle, and moves the cursor there.

If anyone has any other ideas about doing this without snippets, that's welcome too.

top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 4 points 8 months ago

This snippet is available using "rafamadriz/friendly-snippets" plugin for Neovim, the snippet system enables me to write begin then it completes to the exact block you described.

[–] [email protected] 3 points 8 months ago (1 children)

Like someone noted in the vimtex issue you linked, I use UltiSnips together with snippet definitions from vim-snippets, which works pretty well with the begin snippet. vim-snippets includes a bunch more snippets too which I find quite useful, particularly for LaTeX. I don't know the vsnip plugins you mentioned but they can probably do the same.

[–] [email protected] 2 points 8 months ago

I ended up setting up UltiSnips and using the snippet given in the issue.