my-nvim-config/custom-snippets/tex.snippets

51 lines
1.2 KiB
Text
Raw Normal View History

global !p
# def math():
# return vim.eval('vimtex#syntax#in_mathzone()') == '1'
2024-03-16 15:55:28 -05:00
def in_env(lst):
2024-03-15 09:21:36 -05:00
try:
2024-03-16 15:55:28 -05:00
return get_env() in lst
2024-03-15 09:21:36 -05:00
except:
return False
def get_env():
return vim.eval('vimtex#env#get_inner()["name"]')
2024-03-16 01:01:42 -05:00
def delline_exititemize(snip):
cursorline = snip.cursor[0]
del snip.buffer[cursorline]
snip.buffer.append("\n", cursorline + 1)
snip.cursor.set(cursorline + 1, 0)
endglobal
2024-03-13 14:07:20 -05:00
priority -10
2024-03-16 15:55:28 -05:00
context in_env(["itemize", "enumerate"])
snippet "\\item\s*\S+.*" "create next item" rb
`!p snip.rv = match.group(0)`
\item $0
endsnippet
2024-03-16 15:55:28 -05:00
context in_env(["itemize", "enumerate"])
2024-03-16 01:01:42 -05:00
post_jump "delline_exititemize(snip)"
snippet "\\item\s*$" "exit itemize_like envs" rb
endsnippet
2024-03-16 15:55:28 -05:00
snippet "\\begin\{(itemize|enumerate)\}" "multiline begin{} / end{}" rb
2024-03-13 14:07:20 -05:00
\begin{`!p snip.rv = match.group(1)`}
2024-03-16 15:55:28 -05:00
\item $0
2024-03-13 14:07:20 -05:00
\end{`!p snip.rv = match.group(1)`}
endsnippet
2024-03-16 15:55:28 -05:00
snippet "\\begin\{((?!itemize|enumerate))\}" "multiline begin{} / end{}" rb
\begin{`!p snip.rv = match.group(1)`}
2024-03-16 15:55:28 -05:00
$0
\end{`!p snip.rv = match.group(1)`}
endsnippet
2024-03-13 14:07:20 -05:00
priority -20
snippet "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" ri
2024-03-13 14:07:20 -05:00
\begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0
endsnippet