new: Added some advanced item-related snippets

This commit is contained in:
Sayantan Santra 2024-03-14 18:12:35 -05:00
parent 320d1652ee
commit 596cda6697
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
2 changed files with 34 additions and 3 deletions

View file

@ -1,6 +1,6 @@
# My NeoVim Config Files # My NeoVim Config Files
This is basically a copy of my `$XDG_CONFIG_HOME/nvim`. Feel free to use it for configuring your [NeoVim](https://neovim.io/) the way you like it. This is basically a copy of my `$XDG_CONFIG_HOME/nvim`. Feel free to use it for configuring your [NeoVim](https://neovim.io/) installation the way you like it.
[Link to the base repo.](https://git.sintan1729.uk/SinTan1729/my-nvim-config) [Link to the base repo.](https://git.sintan1729.uk/SinTan1729/my-nvim-config)

View file

@ -1,16 +1,47 @@
global !p
# def math():
# return vim.eval('vimtex#syntax#in_mathzone()') == '1'
def itemize_like():
return get_env() in ["itemize", "enumerate"]
def get_env():
return vim.eval('vimtex#env#get_inner()["name"]')
endglobal
priority -10 priority -10
extends tex extends tex
snippet "\\begin\{(\w+)\}" "multiline begin{} / end{}" rbA context itemize_like()
snippet "\\item\s*\S+" "create next item" rb
`!p snip.rv = match.group(0)`
\item $0
endsnippet
context itemize_like()
pre_expand "del snip.buffer[snip.line]; snip.cursor.set(snip.line, len(snip.buffer[snip.line+1])+1)"
snippet "\\item\s*$" "exit itemize_like envs" rb
$0
endsnippet
context not itemize_like()
snippet "\\begin\{(\w+)\}" "multiline begin{} / end{}" rb
\begin{`!p snip.rv = match.group(1)`} \begin{`!p snip.rv = match.group(1)`}
$1 $1
\end{`!p snip.rv = match.group(1)`} \end{`!p snip.rv = match.group(1)`}
endsnippet endsnippet
context itemize_like()
snippet "\\begin\{(\w+)\}" "multiline begin{} / end{}" rb
\begin{`!p snip.rv = match.group(1)`}
\item $1
\end{`!p snip.rv = match.group(1)`}
endsnippet
priority -20 priority -20
snippet "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" riA snippet "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" ri
\begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0 \begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0
endsnippet endsnippet