Updated vimtex and snippets

This commit is contained in:
Minhazul Haque 2024-03-02 19:25:49 +06:00
parent 84a6b218fe
commit 10bf23a6ec
44 changed files with 4209 additions and 69 deletions

90
LuaSnip/all.lua Normal file
View file

@ -0,0 +1,90 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_date = helpers.get_ISO_8601_date
local get_visual = helpers.get_visual
-- A logical OR of `line_begin` and the regTrig '[^%a]trig'
function line_begin_or_non_letter(line_to_cursor, matched_trigger)
local line_begin = line_to_cursor:sub(1, -(#matched_trigger + 1)):match("^%s*$")
local non_letter = line_to_cursor:sub(-(#matched_trigger + 1), -(#matched_trigger + 1)):match('[ :`=%{%(%["]')
return line_begin or non_letter
end
return
{
-- Paired parentheses
s({trig="(", wordTrig = false, snippetType="autosnippet"},
{
t("("),
d(1, get_visual),
t(")"),
}),
-- Paired curly braces
s({trig="{", wordTrig = false, snippetType="autosnippet"},
{
t("{"),
d(1, get_visual),
t("}"),
}),
-- Paired square brackets
s({trig="[", wordTrig = false, snippetType="autosnippet"},
{
t("["),
d(1, get_visual),
t("]"),
}),
-- Paired back ticks
s({trig="sd", snippetType="autosnippet"},
{
f( function(_, snip) return snip.captures[1] end ),
t("`"),
d(1, get_visual),
t("`"),
}),
-- Paired double quotes
s({trig = '"', wordTrig = false, snippetType="autosnippet", priority=2000},
fmta(
'"<>"',
{
d(1, get_visual),
}
),
{condition = line_begin_or_non_letter}
),
-- Paired single quotes
s({trig = "'", wordTrig = false, snippetType="autosnippet", priority=2000},
fmta(
"'<>'",
{
d(1, get_visual),
}
),
{condition = line_begin_or_non_letter}
),
-- -- Today's date in YYYY-MM-DD (ISO 8601) format
-- s({trig = "iso"},
-- {f(get_date)}
-- -- {f(get_ISO_8601_date)}
-- ),
-- Curly braces
s({trig = "df", snippetType="autosnippet"},
fmta(
[[
{
<>
}
]],
{ d(1, get_visual) }
)
),
-- Square braces
s({trig = "dg", snippetType="autosnippet"},
fmta(
[[
[
<>
]
]],
{ d(1, get_visual) }
)
),
}

88
LuaSnip/c/c.lua Normal file
View file

@ -0,0 +1,88 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- MAIN FUNCTION
s({trig = "main", snippetType="autosnippet"},
fmta(
[[
int main()
{
<>
return 0;
}
]],
{ i(1) }
),
{condition = line_begin}
),
-- GENRIC FUNCTION
s({trig = "ff", snippetType="autosnippet"},
fmta(
[[
/*
<>
*/
<>(<>)
{
<>
}
]],
{
i(3),
i(1),
i(2),
d(4, get_visual)
}
),
{condition = line_begin}
),
-- BLOCK COMMENT
s({trig = "cc", snippetType="autosnippet"},
fmta(
[[
/*
<>
*/
]],
{ i(1) }
),
{condition = line_begin}
),
-- DATA STRUCTURE
s({trig = "ss", snippetType="autosnippet"},
fmta(
[[
struct <> {
<>
};
]],
{
i(1),
i(0)
}
)
),
-- -> DEREFERENCE STRUCTURE PROPERTY
s({trig = "--", snippetType="autosnippet", wordTrig=false},
{
t("->")
}
),
-- NULL POINTER SYMBOLIC CONSTANT
s({trig = "00", snippetType="autosnippet", wordTrig=false},
{
t("NULL")
}
),
-- RETURN
s({trig = "rr", snippetType="autosnippet", wordTrig=false},
{
t("return")
},
{ condition = line_begin }
),
}

91
LuaSnip/c/controlflow.lua Normal file
View file

@ -0,0 +1,91 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- IF STATEMENT
s({trig = "iff", snippetType="autosnippet"},
fmta(
[[
if (<>) {
<>
}
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
-- FOR LOOP
s({trig = "fll", snippetType="autosnippet"},
fmta(
[[
for (<>) {
<>
}
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
-- WHILE LOOP
s({trig = "wll", snippetType="autosnippet"},
fmta(
[[
while (<>) {
<>
}
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
-- SWITCH STATEMENT
s({trig = "sc", snippetType="autosnippet"},
fmta(
[[
switch (<>) {
case <>: {
<>
}<>
default: {
<>
}
}
]],
{
i(1),
i(2),
i(3),
i(4),
i(5),
}
),
{condition = line_begin}
),
-- SWITCH CASE
s({trig = "cs", snippetType="autosnippet"},
fmta(
[[
case <>: {
<>
}
]],
{
i(1),
d(2, get_visual),
}
),
{condition = line_begin}
),
}

33
LuaSnip/c/headers.lua Normal file
View file

@ -0,0 +1,33 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- GENERIC HEADER INCLUDE
s({trig = "hh", snippetType="autosnippet"},
fmt(
[[#include <{}.h>]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- STDIO HEADER
s({trig = "hio", snippetType="autosnippet"},
{ t('#include <stdio.h>') },
{condition = line_begin}
),
-- STDLIB HEADER
s({trig = "hlib", snippetType="autosnippet"},
{ t('#include <stdlib.h>') },
{condition = line_begin}
),
-- STRING HEADER
s({trig = "hstr", snippetType="autosnippet"},
{ t('#include <string.h>') },
{condition = line_begin}
),
}

33
LuaSnip/c/io.lua Normal file
View file

@ -0,0 +1,33 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- PRINTF
s({trig = "pp", snippetType="autosnippet"},
fmta(
[[printf("<>"<>);]],
{
i(1),
i(2)
}
),
{ condition = line_begin }
),
-- GETLINE BOILERPLATE
s({trig = "gll", snippetType="autosnippet"},
fmta(
[[
char *line = NULL;
size_t len = 0;
ssize_t nread;
nread = getline(&line, &len, stdin);
<>
free(line);
]],
{ i(0) }
)
),
}

View file

@ -0,0 +1,91 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- IF STATEMENT
s({trig = "iff", snippetType="autosnippet"},
fmta(
[[
if (<>) {
<>
}
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
-- FOR LOOP
s({trig = "fll", snippetType="autosnippet"},
fmta(
[[
for (<>) {
<>
}
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
-- WHILE LOOP
s({trig = "wll", snippetType="autosnippet"},
fmta(
[[
while (<>) {
<>
}
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
-- SWITCH STATEMENT
s({trig = "sc", snippetType="autosnippet"},
fmta(
[[
switch (<>) {
case <>: {
<>
}<>
default: {
<>
}
}
]],
{
i(1),
i(2),
i(3),
i(4),
i(5),
}
),
{condition = line_begin}
),
-- SWITCH CASE
s({trig = "cs", snippetType="autosnippet"},
fmta(
[[
case <>: {
<>
}
]],
{
i(1),
d(2, get_visual),
}
),
{condition = line_begin}
),
}

88
LuaSnip/cpp/cpp.lua Normal file
View file

@ -0,0 +1,88 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- MAIN FUNCTION
s({trig = "main", snippetType="autosnippet"},
fmta(
[[
int main()
{
<>
return 0;
}
]],
{ i(1) }
),
{condition = line_begin}
),
-- GENRIC FUNCTION
s({trig = "ff", snippetType="autosnippet"},
fmta(
[[
/*
<>
*/
<>(<>)
{
<>
}
]],
{
i(3),
i(1),
i(2),
d(4, get_visual)
}
),
{condition = line_begin}
),
-- BLOCK COMMENT
s({trig = "cc", snippetType="autosnippet"},
fmta(
[[
/*
<>
*/
]],
{ i(1) }
),
{condition = line_begin}
),
-- DATA STRUCTURE
s({trig = "ss", snippetType="autosnippet"},
fmta(
[[
struct <> {
<>
};
]],
{
i(1),
i(0)
}
)
),
-- -> DEREFERENCE STRUCTURE PROPERTY
s({trig = "--", snippetType="autosnippet", wordTrig=false},
{
t("->")
}
),
-- NULL POINTER SYMBOLIC CONSTANT
s({trig = "00", snippetType="autosnippet", wordTrig=false},
{
t("NULL")
}
),
-- RETURN
s({trig = "rr", snippetType="autosnippet", wordTrig=false},
{
t("return")
},
{ condition = line_begin }
),
}

33
LuaSnip/cpp/headers.lua Normal file
View file

@ -0,0 +1,33 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- GENERIC HEADER INCLUDE
s({trig = "hh", snippetType="autosnippet"},
fmt(
[[#include <{}>]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- STDIO HEADER
s({trig = "hio", snippetType="autosnippet"},
{ t('#include <iostream>') },
{condition = line_begin}
),
-- MATH HEADER
s({trig = "hmath", snippetType="autosnippet"},
{ t('#include <cmath>') },
{condition = line_begin}
),
-- STRING HEADER
s({trig = "hstr", snippetType="autosnippet"},
{ t('#include <string>') },
{condition = line_begin}
),
}

33
LuaSnip/cpp/io.lua Normal file
View file

@ -0,0 +1,33 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- PRINTF
-- s({trig = "pp", snippetType="autosnippet"},
-- fmta(
-- [[printf("<>"<>);]],
-- {
-- i(1),
-- i(2)
-- }
-- ),
-- { condition = line_begin }
-- ),
-- GETLINE BOILERPLATE
s({trig = "gll", snippetType="autosnippet"},
fmta(
[[
char *line = NULL;
size_t len = 0;
ssize_t nread;
nread = getline(&line, &len, stdin);
<>
free(line);
]],
{ i(0) }
)
),
}

288
LuaSnip/html/html.lua Normal file
View file

@ -0,0 +1,288 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- HEADER
s({trig="h([123456])", regTrig=true, wordTrig=false, snippetType="autosnippet"},
fmt(
[[
<h{} class="{}">{}</h{}>
]],
{
f( function(_, snip) return snip.captures[1] end ),
i(2),
d(1, get_visual),
f( function(_, snip) return snip.captures[1] end ),
}
),
{condition = line_begin}
),
-- GENERTIC INLINE ELEMENT
s({trig = "([^%a])tt", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmt(
[[
{}<{} class="{}">{}</{}>
]],
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2),
d(3, get_visual),
rep(1)
}
)
),
-- GENERTIC TAG
s({trig = "TT", snippetType="autosnippet"},
fmt(
[[
<{}{}>
{}
</{}>
]],
{
i(1),
i(2),
d(3, get_visual),
rep(1)
}
)
),
-- SPAN ELEMENT
s({trig = "([^%l])ss", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmt(
[[
{}<span class="{}">{}</span>
]],
{
f( function(_, snip) return snip.captures[1] end ),
i(2),
d(1, get_visual),
}
)
),
-- FORM TAG
s({trig = "ff", snippetType="autosnippet"},
fmt(
[[
<form{}>
{}
</form>
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
-- PRE TAG
s({trig = "prr", snippetType="autosnippet"},
fmt(
[[
<pre>
{{{{{}}}}}
</pre>
]],
{
d(1, get_visual)
}
)
),
-- PARAGRAPH
s({trig="pp", snippetType="autosnippet"},
fmt(
[[
<p class="{}">{}</p>
]],
{
i(2),
d(1, get_visual),
}
),
{condition = line_begin}
),
-- IMG
s({trig="imgg", snippetType="autosnippet"},
fmt(
[[
<img src="{}" alt="{}" class="{}"/>
]],
{
d(1, get_visual),
i(2),
i(3)
}
)
),
-- CLASS
s({trig=";c", snippetType="autosnippet"},
fmt(
[[
class="{}"
]],
{
d(1, get_visual),
}
)
),
-- UNORDERED LIST
s({trig="ull", snippetType="autosnippet"},
fmt(
[[
<ul>
<li {}>
{}
</li>{}
</ul>
]],
{
i(2),
i(1),
i(0)
}
),
{condition = line_begin}
),
-- LIST ITEM
s({trig="ii", snippetType="autosnippet"},
fmt(
[[
<li {}>
{}
</li>
]],
{
i(2),
d(1, get_visual)
}
),
{condition = line_begin}
),
-- DOCUMENT TEMPLATE
s({trig="base"},
fmt(
[[
<!doctype HTML>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{}</title>
</head>
<body>
{}
</body>
</html>
]],
{
i(1, "FooBar"),
i(0)
}
),
{condition = line_begin}
),
-- SCRIPT
s({trig = "SS", snippetType="autosnippet"},
fmt(
[[
<script{}>
{}{}
</script>
]],
{
i(1),
d(2, get_visual),
i(0)
}
),
{condition = line_begin}
),
-- DIV
s({trig = "dd", snippetType="autosnippet"},
fmt(
[[
<div class="{}">
{}{}
</div>
]],
{
i(2),
d(1, get_visual),
i(0)
}
),
{condition = line_begin}
),
-- DIV with ID for practicing Vue
s({trig = "dii", snippetType="autosnippet"},
fmt(
[[
<div id="{}">
{}
</div>
]],
{
i(1),
i(0)
}
),
{condition = line_begin}
),
-- INPUT ELEMENT
s({trig = "inn", snippetType="autosnippet"},
fmt(
[[
<input type="{}" id="{}" />
]],
{
i(1),
i(2)
}
)
),
-- LABEL
s({trig = "lbl", snippetType="autosnippet"},
fmt(
[[
<label for="{}">
{}
</label>
]],
{
i(1),
d(2, get_visual)
}
)
),
-- BUTTON
s({trig = "bb", snippetType="autosnippet"},
fmt(
[[
<button type="{}" {}>
{}
</button>
]],
{
i(1),
i(2),
d(3, get_visual),
}
),
{condition = line_begin}
),
-- STRONG ELEMENT
s({trig = "tbb", snippetType="autosnippet"},
fmt(
[[
<strong>{}</strong>
]],
{
d(1, get_visual),
}
)
),
}

74
LuaSnip/html/tables.lua Normal file
View file

@ -0,0 +1,74 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- TABLE
s({trig="tbl", snippetType="autosnippet"},
fmt(
[[
<table>
{}
</table>
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- TABLE HEADER
s({trig="tbh", snippetType="autosnippet"},
fmt(
[[
<thead>
{}
</thead>
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- TABLE BODY
s({trig="tbb", snippetType="autosnippet"},
fmt(
[[
<tbody>
{}
</tbody>
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- TABLE DATA
s({trig="tdd", snippetType="autosnippet"},
fmt(
[[
<td>{}</td>
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- TABLE HEADER
s({trig="thh", snippetType="autosnippet"},
fmt(
[[
<th>{}</th>
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
}

236
LuaSnip/java.lua Normal file
View file

@ -0,0 +1,236 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- main function
s({trig = "mm", snippetType="autosnippet"},
fmta(
[[
public static void main(String[] args) {
<>
}
]],
{ i(0) }
),
{condition = line_begin}
),
-- CURLY BRACES
s({trig = "df", snippetType="autosnippet", priority=1000},
fmta(
[[
{
<>
}
]],
{ d(1, get_visual) }
)
),
-- class
s({trig = "pcc", snippetType="autosnippet"},
fmta(
[[
public class <>
{
<>
}
]],
{ i(1), i(0) }
),
{condition = line_begin}
),
-- constructor
s({trig = "puu", snippetType="autosnippet"},
fmta(
[[
public <>(<>) {
<>
}
]],
{ i(1), i(2), i(3) }
),
{condition = line_begin}
),
-- New object
s({trig = "nn", snippetType="autosnippet"},
fmta(
[[
<> <> = new <>(<>);
]],
{ i(1), i(2), rep(1), i(3) }
),
{condition = line_begin}
),
-- public function
s({trig = "pff", snippetType="autosnippet"},
fmta(
[[
public <> <>(<>) {
<>
}
]],
{ i(1), i(2), i(3), i(4) }
),
{condition = line_begin}
),
-- public static function
s({trig = "psf", snippetType="autosnippet"},
fmta(
[[
public static <> <>(<>) {
<>
}
]],
{ i(1), i(2), i(3), i(4) }
),
{condition = line_begin}
),
-- private function
s({trig = "pvv", snippetType="autosnippet"},
fmta(
[[
private <> <>(<>) {
<>
}
]],
{ i(1), i(2), i(3), i(4) }
),
{condition = line_begin}
),
-- if statement
s({trig = "iff", snippetType="autosnippet"},
fmta(
[[
if (<>) <>
]],
{
i(1),
c(2, {sn(nil, {t("{"), t({"", " "}), i(1, ""), t({"", "}"})}), t("")}),
}
),
{condition = line_begin}
),
-- for loop with int i counter and optional statement braces
s({trig = "fii", snippetType="autosnippet"},
fmta(
[[
for (int i = 0; i <>; i++) <>
]],
{
i(1),
c(2, {sn(nil, {t("{"), t({"", " "}), i(1, ""), t({"", "}"})}), t("")}),
}
),
{condition = line_begin}
),
-- for loop with int j counter and optional statement braces
s({trig = "fjj", snippetType="autosnippet"},
fmta(
[[
for (int j = 0; j <>; j++) <>
]],
{
i(1),
c(2, {sn(nil, {t("{"), t({"", " "}), i(1, ""), t({"", "}"})}), t("")}),
}
),
{condition = line_begin}
),
-- for loop with blank arguments
s({trig = "frr", snippetType="autosnippet"},
fmta(
[[
for (<>) <>
]],
{
i(1),
c(2, {sn(nil, {t("{"), t({"", " "}), i(1, ""), t({"", "}"})}), t("")}),
}
),
{condition = line_begin}
),
-- while loop
s({trig = "wll", snippetType="autosnippet"},
fmta(
[[
while (<>) <>
]],
{
i(1),
c(2, {sn(nil, {t("{"), t({"", " "}), i(1, ""), t({"", "}"})}), t("")}),
}
),
{condition = line_begin}
),
-- block comment
s({trig = "cc", snippetType="autosnippet"},
fmta(
[[
/**
* <>
*/
]],
{ i(1) }
),
{condition = line_begin}
),
-- println using algs4 StdOut
s({trig = "pp", snippetType="autosnippet"},
fmta(
[[
StdOut.println(<>);
]],
{ d(1, get_visual) }
),
{condition = line_begin}
),
-- Integer.parseInt()
s({trig = "ipi", snippetType="autosnippet"},
fmta(
[[
Integer.parseInt(<>)
]],
{ d(1, get_visual) }
)
),
-- Double.parseDouble()
s({trig = "dpd", snippetType="autosnippet"},
fmta(
[[
Double.parseDouble(<>)
]],
{ d(1, get_visual) }
)
),
-- Import from algs4
s({trig = ";ii", snippetType="autosnippet"},
fmta(
[[
import edu.princeton.cs.algs4.<>;
]],
{ i(1) }
),
{condition = line_begin}
),
-- Import StdIn from algs4
s({trig = ";in", snippetType="autosnippet"},
{t("import edu.princeton.cs.algs4.StdIn;")},
{condition = line_begin}
),
-- Import StdOut from algs4
s({trig = ";io", snippetType="autosnippet"},
{t("import edu.princeton.cs.algs4.StdOut;")},
{condition = line_begin}
),
-- array length
s({trig = ";l", wordTrig=false, snippetType="autosnippet"},
fmta(
[[
.length
]],
{}
)
),
}

36
LuaSnip/javascript.lua Normal file
View file

@ -0,0 +1,36 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- ALERT
s({trig = "aa", snippetType="autosnippet"},
fmta(
[[
alert(<>);
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- LOG TO CONSOLE
s({trig = "PP", snippetType="autosnippet"},
fmta(
[[
console.log(<>);
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
}

32
LuaSnip/lua.lua Normal file
View file

@ -0,0 +1,32 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- PRINT
s({trig="pp", snippetType="autosnippet"},
fmta(
[[
print(<>)
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- DO RETURN END
s({trig="XX", snippetType="autosnippet"},
fmta(
[[
do return end
]],
{
}
),
{condition = line_begin}
),
}

36
LuaSnip/make.lua Normal file
View file

@ -0,0 +1,36 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- VARIABLE
s({trig = "vv", wordTrig=false, snippetType="autosnippet"},
fmta(
[[
$(<>)
]],
{
d(1, get_visual),
}
)
),
-- ECHO
s({trig = "pp", wordTrig=false, snippetType="autosnippet"},
fmta(
[[
@echo
]],
{ }
)
),
-- PHONY target
s({trig = "PP", wordTrig=false, snippetType="autosnippet"},
fmta(
[[
.PHONY:
]],
{ }
)
),
}

View file

@ -0,0 +1,141 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
-- Return snippet tables
return
{
-- Fenced block of code
s({trig="cc", snippetType = "autosnippet"},
fmta(
[[
```<>
<>
```
]],
{
i(1),
d(2, get_visual),
}
),
{condition = line_begin}
),
-- HTML CODE BLOCK
s({trig="html"},
fmta(
[[
```html
<>
```
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- PHP CODE BLOCK
s({trig="phpp", snippetType="autosnippet"},
fmt(
[[
```php
<?php
{}
```
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- PYTHON CODE BLOCK
s({trig="pyy", snippetType="autosnippet"},
fmt(
[[
```python
{}
```
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- BEANCOUNT CODE BLOCK
s({trig="bc"},
fmt(
[[
```beancount
{}
```
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- BASH CODE BLOCK
s({trig="shh", snippetType="autosnippet"},
fmt(
[[
```bash
{}
```
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- SQL CODE BLOCK
s({trig="qq", snippetType="autosnippet"},
fmt(
[[
```sql
{}
```
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- JAVASCRIPT CODE BLOCK
s({trig="jss", snippetType="autosnippet"},
fmt(
[[
```javascript
{}
```
]],
{
d(1, get_visual)
}
),
{condition = line_begin}
),
-- VUE CODE BLOCK
s({trig="vuu", snippetType="autosnippet"},
fmt(
[[
```vue
{}<script setup>
{}
</script>
```
]],
{
i(1),
d(2, get_visual)
}
),
{condition = line_begin}
),
}

View file

@ -0,0 +1,68 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
-- Return snippet tables
return
{
-- TODO NOTE
s({trig="TODOO", snippetType="autosnippet"},
{
t("**TODO:** "),
}
),
-- LINK; CAPTURE TEXT IN VISUAL
s({trig="LL", wordTrig=true, snippetType="autosnippet"},
fmta(
[[[<>](<>)]],
{
d(1, get_visual),
i(2),
}
)
),
-- LINK; CAPTURE URL IN VISUAL
s({trig="LU", wordTrig=true, snippetType="autosnippet"},
fmta(
[[[<>](<>)]],
{
i(1),
d(2, get_visual),
}
)
),
-- BOLDFACE TEXT
s({trig="tbb", snippetType="autosnippet"},
fmta(
[[**<>**]],
{
d(1, get_visual),
}
)
),
-- ITALIC TEXT
s({trig="tii", snippetType="autosnippet"},
fmta(
[[*<>*]],
{
d(1, get_visual),
}
)
),
-- UNDERLINED TEXT
s({trig="uu", snippetType="autosnippet"},
fmt(
[[<u>{}</u>]],
{
d(1, get_visual),
}
)
),
-- Hack to remove indentation in bulleted lists
s({trig=" --", snippetType="autosnippet"},
{t("- ")},
{condition = line_begin}
),
}

109
LuaSnip/python/docs.lua Normal file
View file

@ -0,0 +1,109 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- FUNCTION PARAMETERS for use in docstrings, with heading
s({trig="PP", snippetType="autosnippet"},
fmta(
[[
Parameters
----------
<> : <>
<>
]],
{
i(1),
i(2),
i(3)
}
),
{condition = line_begin}
),
-- FUNCTION RETURNS for use in docstrings, with heading
s({trig="RR", snippetType="autosnippet"},
fmta(
[[
Returns
----------
<> : <>
<>
]],
{
i(1),
i(2),
i(3)
}
),
{condition = line_begin}
),
-- NOTES docstring section
s({trig="NN", snippetType="autosnippet"},
fmta(
[[
NOTES
-----
]],
{ }
),
{condition = line_begin}
),
-- PRE-CONDITION docstring section
s({trig="prr", snippetType="autosnippet"},
fmta(
[[
Pre-Conditions
--------------
]],
{ }
),
{condition = line_begin}
),
-- -- POST-CONDITION docstring section
-- s({trig="pss", snippetType="autosnippet"},
-- fmta(
-- [[
-- Post-Conditions
-- ---------------
-- ]],
-- { }
-- ),
-- {condition = line_begin}
-- ),
-- FUNCTION PARAMETER for use in docstrings
s({trig="::", snippetType="autosnippet"},
fmta(
[[
<> : <>
<>
]],
{
i(1),
i(2),
i(3)
}
),
{condition = line_begin}
),
-- LONG STRING OF DASHES FOR COMMENTS
s({trig = "--", snippetType="autosnippet"},
{t('# -------------------------------------------------------------------- #')},
{condition = line_begin}
),
-- MULTILINE COMMENT
s({trig = "cc", snippetType="autosnippet"},
fmta(
[[
"""
<>
"""
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
}

125
LuaSnip/python/mpl.lua Normal file
View file

@ -0,0 +1,125 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- NEW FIGURE, AXES
s({trig="fx", snippetType="autosnippet"},
fmta(
[[fig, ax = plt.subplots(<>)]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- plt.
s({trig=";p", snippetType="autosnippet"},
{t("plt.")}
),
-- plt.plot()
s({trig="pll", snippetType="autosnippet"},
fmta(
[[plt.plot(<>)]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- plt.show()
s({trig="pss", snippetType="autosnippet"},
fmta(
[[plt.show()]],
{ }
),
{condition = line_begin}
),
-- AXIS PLOT
s({trig="xp", snippetType="autosnippet"},
fmta(
[[ax.plot(<>)]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- AXIS SET_XLABEL
s({trig="xxl", snippetType="autosnippet"},
fmta(
[[ax.set_xlabel(<>)]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- AXIS SET_YLABEL
s({trig="xyl", snippetType="autosnippet"},
fmta(
[[ax.set_ylabel(<>)]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- AXIS SET_TITLE
s({trig="xt", snippetType="autosnippet"},
fmta(
[[ax.set_title(<>)]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- TIGHT LAYOUT
s({trig="ttl", snippetType="autosnippet"},
{t("plt.tight_layout()")},
{condition = line_begin}
),
-- STEM PLOT
s({trig="stem", snippetType="autosnippet"},
fmta(
[[
(markers, stemlines, baseline) = ax.stem(<>)
plt.setp(markers, marker='o', markerfacecolor=<>, markeredgecolor="none", markersize=6)
plt.setp(baseline, color=<>, linestyle="-")
plt.setp(stemlines, linestyle="--", color=<>, linewidth=2)
]],
{
i(1),
i(2),
i(3),
i(4)
}
),
{condition = line_begin}
),
-- REMOVE SPINE FUNCTION
s({trig="spines"},
fmta(
[[
def remove_spines(ax):
"""
Removes top and right spines from the inputted Matplotlib axis. This is for
aesthetic purposes only and has no practical function.
"""
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
]],
{
}
),
{condition = line_begin}
),
}

19
LuaSnip/python/numpy.lua Normal file
View file

@ -0,0 +1,19 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- NP.LOADTXT
s({trig="nlt", snippetType="autosnippet"},
fmta(
[[
np.loadtxt(<>)
]],
{
d(1, get_visual),
}
)
),
}

163
LuaSnip/python/python.lua Normal file
View file

@ -0,0 +1,163 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- PRINT STATEMENT
s({trig="pp", snippetType="autosnippet"},
fmta(
[[print(<>)]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- MAIN FUNCTION
s({trig="main", snippetType="autosnippet"},
fmta(
[[
if __name__ == "__main__":
<>
]],
{
d(1, get_visual),
}
),
{condition = line_begin}
),
-- CLASS
s({trig="class"},
fmta(
[[
class <>(<>):
def __init__(self<>):
<>
]],
{
i(1),
i(2),
i(3),
i(4),
}
),
{condition = line_begin}
),
-- EXIT MAIN FUNCTION with sys.exit()
s({trig="XX", snippetType="autosnippet"},
{ t("sys.exit()") },
{condition = line_begin}
),
-- FUNCTION DEFINITION WITH CHOICE NODE DOCSTRING
-- The idea is to let you choose if you want to use the docstring or not
s({trig="ff", snippetType="autosnippet"},
fmta(
[[
def <>(<>):
<><>
]],
{
i(1),
i(2),
c(3, {sn(nil, {t({"\"\"\"", ""}), t(" "), i(1, ""), t({"", " \"\"\"", " "})}), t("")}),
-- t(" "),
d(4, get_visual),
}
),
{condition = line_begin}
),
-- TIME, i.e. snippet for timing code execution
s({trig="time"},
fmta(
[[
start = time.time()
<>
end = time.time()
]],
{
d(1, get_visual),
}
)
),
-- for _ in range()
s({trig="frr", snippetType = "autosnippet"},
fmta(
[[
for <> in range(<>):
<>
]],
{
i(1),
i(2),
i(3)
}
),
{condition = line_begin}
),
-- IF STATEMENT
s({trig="iff", snippetType = "autosnippet"},
fmta(
[[
if <>:
<>
]],
{
i(1),
d(2, get_visual),
}
),
{condition = line_begin}
),
-- with open(filename) as file
s({trig="wof", snippetType = "autosnippet"},
fmta(
[[
with open(<>) as <>:
<>
]],
{
i(1),
i(2, 'file'),
i(0),
}
),
{condition = line_begin}
),
-- RETURN STATEMENT
s({trig = ";r", snippetType = "autosnippet"},
{ t("return") },
{ condition = line_begin }
),
-- KWARGS STATEMENT
s({trig = ";k", snippetType = "autosnippet", wordTrig=false},
{ t("kwargs") }
),
-- KWARGS.GET
s({trig="kgg", snippetType = "autosnippet"},
fmta(
[[
kwargs.get('<>', '<>')
]],
{
d(1, get_visual),
i(2)
}
)
),
-- SELF (for use in classes)
s({trig = ";s", snippetType = "autosnippet"},
{ t("self.") }
),
-- SELF (for use in classes) without dot
s({trig = ";S", snippetType = "autosnippet"},
{ t("self") }
),
-- TRACEBACK
s({trig = "tbb", snippetType = "autosnippet"},
{ t("print(traceback.format_exc())") },
{ condition = line_begin }
),
}

131
LuaSnip/python/torch.lua Normal file
View file

@ -0,0 +1,131 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- COMMON IMPORTS
s({trig="itorch"},
fmt(
[[
import torch
from torch import nn
from torch.utils.data import Dataset, DataLoader
]],
{
}
),
{condition = line_begin}
),
-- NETWORK MODEL TEMPLATE
s({trig="model"},
fmta(
[[
class FooNet(nn.Module):
def __init__(self):
super(FooNet, self).__init__()
<>
def forward(self, x):
<>
]],
{
i(1),
i(2)
}
),
{condition = line_begin}
),
-- CUSTOM DATASET TEMPLATE
s({trig="dataset"},
fmta(
[[
class FooDataset(Dataset):
def __init__(self, ...):
<>
def __getitem__(self, index):
# Returns the (feature vector, label) tuple at index `index`
<>
def __len__(self):
# Return number of instances in dataset
<>
]],
{
i(1),
i(2),
i(3)
}
),
{condition = line_begin}
),
-- SGD OPTIMIZER
s({trig="optim"},
fmta(
[[
optim = torch.optim.SGD(model.parameters(), lr=<>)
]],
{
i(1),
}
),
{condition = line_begin}
),
-- TRAINING LOOP TEMPLATE
s({trig="train"},
fmta(
[[
def train_loop(dataloader, model, loss_fn, optim):
N = len(dataloader.dataset)
# Loop over all minibatches in dataset
for mb, (X, y) in enumerate(dataloader):
# Compute prediction and loss
pred = model(X)
loss = loss_fn(pred, y)
# Backpropagation
optimizer.zero_grad()
loss.backward()
optimizer.step()
# Log loss and number of instances trained
if mb % <> == 0:
loss, n = loss.item(), mb * len(X)
print("loss: {:.7f} [{:5d}/{:5d}]".format(loss, n, N))
]],
{
i(1, "100"),
}
),
{condition = line_begin}
),
-- TEST LOOP TEMPLATE
s({trig="test"},
fmta(
[[
def test_loop(dataloader, model, loss_fn):
N = len(dataloader.dataset)
num_batches = len(dataloader)
test_loss = 0
correct_preds = 0
with torch.no_grad():
for X, y in dataloader:
pred = model(X)
test_loss += loss_fn(pred, y).item()
correct_preds += (pred.argmax(1) == y).type(torch.float).sum().item()
test_loss /= num_batches
print("Test Error: \n Accuracy: {:.1f}%\n Avg loss per minibatch: {:8f} \n".format((100*correct_preds/N), test_loss))
]],
{ }
),
{condition = line_begin}
),
}

117
LuaSnip/sh.lua Normal file
View file

@ -0,0 +1,117 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
s({trig = "doc"},
fmt(
[[
# NAME
# {} - {}
#
# SYNOPSIS
# {} {}
]],
{
i(1, "name"),
i(2, "description"),
rep(1),
i(3, "usage"),
}
),
{condition = line_begin}
),
-- /bin/bash shebang
s({trig = "!!", snippetType="autosnippet"},
{t("#!/bin/bash")},
{condition = line_begin}
),
s({trig = "fl", snippetType="autosnippet"},
fmt(
[[
for {} in {}; do
{}
done
]],
{
i(1),
i(2),
i(0)
}
),
{condition = line_begin}
),
s({trig = "read"},
fmt(
[=[
while read line
do
[[ -z "${line}" ]] && continue
[[ "${line}" = \#* ]] && continue
echo "${line}"
()
done < ()
]=],
{
i(2),
i(1, "myfile.txt")
},
{ delimiters = "()"}
),
{condition = line_begin}
),
-- IF STATEMENT
s({trig = "iff", snippetType="autosnippet"},
fmta(
[=[
if [[ <> ]]; then
<>
fi
]=],
{
i(1),
i(0)
}
),
{condition = line_begin}
),
-- VARIABLE
s({trig = "vv", wordTrig=false, snippetType="autosnippet"},
fmta(
[[
${<>}
]],
{
d(1, get_visual),
}
)
),
-- ECHO
s({trig = "pp", snippetType="autosnippet"},
fmta(
[[
echo "<>"
]],
{
d(1, get_visual),
}
)
),
s({trig = "ext"},
fmta(
[[
${<>%.<>}
]],
{
i(1, "var"),
i(2, "ext"),
}
)
),
s({trig = "XX", snippetType="autosnippet"},
{t("exit")},
{condition = line_begin}
),
}

131
LuaSnip/sql.lua Normal file
View file

@ -0,0 +1,131 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return
{
-- SELECT
s({trig = ";s", wordTrig=false, snippetType="autosnippet"},
{t("SELECT ")}
),
-- FROM
s({trig = ";f", wordTrig=false, snippetType="autosnippet"},
{t("FROM ")}
),
-- DISTINCT
s({trig = ";di", wordTrig=false, snippetType="autosnippet"},
{t("DISTINCT ")}
),
-- DROP
s({trig = ";dr", wordTrig=false, snippetType="autosnippet"},
{t("DROP ")}
),
-- WITH DELIMITER
s({trig = ";wd", wordTrig=false, snippetType="autosnippet"},
{t("WITH DELIMITER ")}
),
-- HEADER CSV
s({trig = ";hc", wordTrig=false, snippetType="autosnippet"},
{t("HEADER CSV ")}
),
-- CREATE TABLE
s({trig = ";ct", wordTrig=false, snippetType="autosnippet"},
{t("CREATE TABLE ")}
),
-- CREATE TEMPORARY TABLE
s({trig = ";cp", wordTrig=false, snippetType="autosnippet"},
{t("CREATE TEMPORARY TABLE ")}
),
-- UPDATE
s({trig = ";u", wordTrig=false, snippetType="autosnippet"},
{t("UPDATE ")}
),
-- NULL
s({trig = ";nl", wordTrig=false, snippetType="autosnippet"},
{t("NULL ")}
),
-- NOT NULL
s({trig = ";nn", wordTrig=false, snippetType="autosnippet"},
{t("NOT NULL ")}
),
}
-- ADD Adds a column in an existing table
-- ADD CONSTRAINT Adds a constraint after a table is already created
-- ALL Returns true if all of the subquery values meet the condition
-- ALTER Adds, deletes, or modifies columns in a table, or changes the data type of a column in a table
-- ALTER COLUMN Changes the data type of a column in a table
-- ALTER TABLE Adds, deletes, or modifies columns in a table
-- AND Only includes rows where both conditions is true
-- ANY Returns true if any of the subquery values meet the condition
-- AS Renames a column or table with an alias
-- ASC Sorts the result set in ascending order
-- BACKUP DATABASE Creates a back up of an existing database
-- BETWEEN Selects values within a given range
-- CASE Creates different outputs based on conditions
-- CHECK A constraint that limits the value that can be placed in a column
-- COLUMN Changes the data type of a column or deletes a column in a table
-- CONSTRAINT Adds or deletes a constraint
-- CREATE Creates a database, index, view, table, or procedure
-- CREATE DATABASE Creates a new SQL database
-- CREATE INDEX Creates an index on a table (allows duplicate values)
-- CREATE OR REPLACE VIEW Updates a view
-- CREATE TABLE Creates a new table in the database
-- CREATE PROCEDURE Creates a stored procedure
-- CREATE UNIQUE INDEX Creates a unique index on a table (no duplicate values)
-- CREATE VIEW Creates a view based on the result set of a SELECT statement
-- DATABASE Creates or deletes an SQL database
-- DEFAULT A constraint that provides a default value for a column
-- DELETE Deletes rows from a table
-- DESC Sorts the result set in descending order
-- DISTINCT Selects only distinct (different) values
-- DROP Deletes a column, constraint, database, index, table, or view
-- DROP COLUMN Deletes a column in a table
-- DROP CONSTRAINT Deletes a UNIQUE, PRIMARY KEY, FOREIGN KEY, or CHECK constraint
-- DROP DATABASE Deletes an existing SQL database
-- DROP DEFAULT Deletes a DEFAULT constraint
-- DROP INDEX Deletes an index in a table
-- DROP TABLE Deletes an existing table in the database
-- DROP VIEW Deletes a view
-- EXEC Executes a stored procedure
-- EXISTS Tests for the existence of any record in a subquery
-- FOREIGN KEY A constraint that is a key used to link two tables together
-- FROM Specifies which table to select or delete data from
-- FULL OUTER JOIN Returns all rows when there is a match in either left table or right table
-- GROUP BY Groups the result set (used with aggregate functions: COUNT, MAX, MIN, SUM, AVG)
-- HAVING Used instead of WHERE with aggregate functions
-- IN Allows you to specify multiple values in a WHERE clause
-- INDEX Creates or deletes an index in a table
-- INNER JOIN Returns rows that have matching values in both tables
-- INSERT INTO Inserts new rows in a table
-- INSERT INTO SELECT Copies data from one table into another table
-- IS NULL Tests for empty values
-- IS NOT NULL Tests for non-empty values
-- JOIN Joins tables
-- LEFT JOIN Returns all rows from the left table, and the matching rows from the right table
-- LIKE Searches for a specified pattern in a column
-- LIMIT Specifies the number of records to return in the result set
-- NOT Only includes rows where a condition is not true
-- NOT NULL A constraint that enforces a column to not accept NULL values
-- OR Includes rows where either condition is true
-- ORDER BY Sorts the result set in ascending or descending order
-- OUTER JOIN Returns all rows when there is a match in either left table or right table
-- PRIMARY KEY A constraint that uniquely identifies each record in a database table
-- PROCEDURE A stored procedure
-- RIGHT JOIN Returns all rows from the right table, and the matching rows from the left table
-- ROWNUM Specifies the number of records to return in the result set
-- SELECT Selects data from a database
-- SELECT DISTINCT Selects only distinct (different) values
-- SELECT INTO Copies data from one table into a new table
-- SELECT TOP Specifies the number of records to return in the result set
-- SET Specifies which columns and values that should be updated in a table
-- TABLE Creates a table, or adds, deletes, or modifies columns in a table, or deletes a table or data inside a table
-- TOP Specifies the number of records to return in the result set
-- TRUNCATE TABLE Deletes the data inside a table, but not the table itself
-- UNION Combines the result set of two or more SELECT statements (only distinct values)
-- UNION ALL Combines the result set of two or more SELECT statements (allows duplicate values)
-- UNIQUE A constraint that ensures that all values in a column are unique
-- UPDATE Updates existing rows in a table
-- VALUES Specifies the values of an INSERT INTO statement
-- VIEW Creates, updates, or deletes a view
-- WHERE Filters a result set to include only records that fulfill a specified condition

92
LuaSnip/tex/delimiter.lua Normal file
View file

@ -0,0 +1,92 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
-- Math context detection
local tex = {}
tex.in_mathzone = function() return vim.fn['vimtex#syntax#in_mathzone']() == 1 end
tex.in_text = function() return not tex.in_mathzone() end
-- Return snippet tables
return
{
-- LEFT/RIGHT PARENTHESES
s({trig = "([^%a])l%(", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\left(<>\\right)",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- LEFT/RIGHT SQUARE BRACES
s({trig = "([^%a])l%[", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\left[<>\\right]",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- LEFT/RIGHT CURLY BRACES
s({trig = "([^%a])l%{", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\left\\{<>\\right\\}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- BIG PARENTHESES
s({trig = "([^%a])b%(", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\big(<>\\big)",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- BIG SQUARE BRACES
s({trig = "([^%a])b%[", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\big[<>\\big]",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- BIG CURLY BRACES
s({trig = "([^%a])b%{", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\big\\{<>\\big\\}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- ESCAPED CURLY BRACES
s({trig = "([^%a])\\%{", regTrig = true, wordTrig = false, snippetType="autosnippet", priority=2000},
fmta(
"<>\\{<>\\}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- LATEX QUOTATION MARK
s({trig = "``", snippetType="autosnippet"},
fmta(
"``<>''",
{
d(1, get_visual),
}
)
),
}

View file

@ -0,0 +1,193 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
-- Math context detection
local tex = {}
tex.in_mathzone = function() return vim.fn['vimtex#syntax#in_mathzone']() == 1 end
tex.in_text = function() return not tex.in_mathzone() end
local line_begin = require("luasnip.extras.expand_conditions").line_begin
-- Return snippet tables
return
{
-- GENERIC ENVIRONMENT
s({trig="new", snippetType="autosnippet"},
fmta(
[[
\begin{<>}
<>
\end{<>}
]],
{
i(1),
d(2, get_visual),
rep(1),
}
),
{condition = line_begin}
),
-- ENVIRONMENT WITH ONE EXTRA ARGUMENT
s({trig="n2", snippetType="autosnippet"},
fmta(
[[
\begin{<>}{<>}
<>
\end{<>}
]],
{
i(1),
i(2),
d(3, get_visual),
rep(1),
}
),
{ condition = line_begin }
),
-- ENVIRONMENT WITH TWO EXTRA ARGUMENTS
s({trig="n3", snippetType="autosnippet"},
fmta(
[[
\begin{<>}{<>}{<>}
<>
\end{<>}
]],
{
i(1),
i(2),
i(3),
d(4, get_visual),
rep(1),
}
),
{ condition = line_begin }
),
-- TOPIC ENVIRONMENT (my custom tcbtheorem environment)
s({trig="nt", snippetType="autosnippet"},
fmta(
[[
\begin{topic}{<>}{<>}
<>
\end{topic}
]],
{
i(1),
i(2),
d(3, get_visual),
}
),
{ condition = line_begin }
),
-- EQUATION
s({trig="nn", snippetType="autosnippet"},
fmta(
[[
\begin{equation*}
<>
\end{equation*}
]],
{
i(1),
}
),
{ condition = line_begin }
),
-- SPLIT EQUATION
s({trig="ss", snippetType="autosnippet"},
fmta(
[[
\begin{equation*}
\begin{split}
<>
\end{split}
\end{equation*}
]],
{
d(1, get_visual),
}
),
{ condition = line_begin }
),
-- ALIGN
s({trig="all", snippetType="autosnippet"},
fmta(
[[
\begin{align*}
<>
\end{align*}
]],
{
i(1),
}
),
{condition = line_begin}
),
-- ITEMIZE
s({trig="itt", snippetType="autosnippet"},
fmta(
[[
\begin{itemize}
\item <>
\end{itemize}
]],
{
i(0),
}
),
{condition = line_begin}
),
-- ENUMERATE
s({trig="enn", snippetType="autosnippet"},
fmta(
[[
\begin{enumerate}
\item <>
\end{enumerate}
]],
{
i(0),
}
)
),
-- INLINE MATH
s({trig = "([^%l])mm", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>$<>$",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- INLINE MATH ON NEW LINE
s({trig = "^mm", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"$<>$",
{
i(1),
})),
-- FIGURE
s({trig = "fig"},
fmta(
[[
\begin{figure}[htb!]
\centering
\includegraphics[width=<>\linewidth]{<>}
\caption{<>}
\label{fig:<>}
\end{figure}
]],
{
i(1),
i(2),
i(3),
i(4),
}
),
{ condition = line_begin }
),
}

105
LuaSnip/tex/fonts.lua Normal file
View file

@ -0,0 +1,105 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
-- A logical OR of `line_begin` and the regTrig '[^%a]trig'
function line_begin_or_non_letter(line_to_cursor, matched_trigger)
local line_begin = line_to_cursor:sub(1, -(#matched_trigger + 1)):match("^%s*$")
local non_letter = line_to_cursor:sub(-(#matched_trigger + 1), -(#matched_trigger + 1)):match("[^%a]")
return line_begin or non_letter
end
-- Math context detection
local tex = {}
tex.in_mathzone = function() return vim.fn['vimtex#syntax#in_mathzone']() == 1 end
tex.in_text = function() return not tex.in_mathzone() end
local line_begin = function(line_to_cursor, matched_trigger)
-- +1 because `string.sub("abcd", 1, -2)` -> abc
return line_to_cursor:sub(1, -(#matched_trigger + 1)):match("^%s*$")
end
-- Return snippet tables
return
{
-- TYPEWRITER i.e. \texttt
s({trig = "([^%a])tt", regTrig = true, wordTrig = false, snippetType="autosnippet", priority=2000},
fmta(
"<>\\texttt{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_text}
),
-- ITALIC i.e. \textit
s({trig = "([^%a])tii", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\textit{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- BOLD i.e. \textbf
s({trig = "tbb", snippetType="autosnippet"},
fmta(
"\\textbf{<>}",
{
d(1, get_visual),
}
)
),
-- MATH ROMAN i.e. \mathrm
s({trig = "([^%a])rmm", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\mathrm{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- MATH CALIGRAPHY i.e. \mathcal
s({trig = "([^%a])mcc", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\mathcal{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- MATH BOLDFACE i.e. \mathbf
s({trig = "([^%a])mbf", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\mathbf{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- MATH BLACKBOARD i.e. \mathbb
s({trig = "([^%a])mbb", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\mathbb{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
)
),
-- REGULAR TEXT i.e. \text (in math environments)
s({trig = "([^%a])tee", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\text{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{ condition = tex.in_mathzone }
),
}

140
LuaSnip/tex/greek.lua Normal file
View file

@ -0,0 +1,140 @@
-- Return snippet tables
return
{
s({trig=";a", snippetType="autosnippet"},
{
t("\\alpha"),
}),
s({trig=";b", snippetType="autosnippet"},
{
t("\\beta"),
}),
s({trig=";g", snippetType="autosnippet"},
{
t("\\gamma"),
}),
s({trig=";G", snippetType="autosnippet"},
{
t("\\Gamma"),
}),
s({trig=";d", snippetType="autosnippet"},
{
t("\\delta"),
}),
s({trig=";D", snippetType="autosnippet"},
{
t("\\Delta"),
}),
s({trig=";e", snippetType="autosnippet"},
{
t("\\epsilon"),
}),
s({trig=";ve", snippetType="autosnippet"},
{
t("\\varepsilon"),
}),
s({trig=";z", snippetType="autosnippet"},
{
t("\\zeta"),
}),
s({trig=";h", snippetType="autosnippet"},
{
t("\\eta"),
}),
s({trig=";o", snippetType="autosnippet"},
{
t("\\theta"),
}),
s({trig=";vo", snippetType="autosnippet"},
{
t("\\vartheta"),
}),
s({trig=";O", snippetType="autosnippet"},
{
t("\\Theta"),
}),
s({trig=";k", snippetType="autosnippet"},
{
t("\\kappa"),
}),
s({trig=";l", snippetType="autosnippet"},
{
t("\\lambda"),
}),
s({trig=";L", snippetType="autosnippet"},
{
t("\\Lambda"),
}),
s({trig=";m", snippetType="autosnippet"},
{
t("\\mu"),
}),
s({trig=";n", snippetType="autosnippet"},
{
t("\\nu"),
}),
s({trig=";x", snippetType="autosnippet"},
{
t("\\xi"),
}),
s({trig=";X", snippetType="autosnippet"},
{
t("\\Xi"),
}),
s({trig=";i", snippetType="autosnippet"},
{
t("\\pi"),
}),
s({trig=";I", snippetType="autosnippet"},
{
t("\\Pi"),
}),
s({trig=";r", snippetType="autosnippet"},
{
t("\\rho"),
}),
s({trig=";s", snippetType="autosnippet"},
{
t("\\sigma"),
}),
s({trig=";S", snippetType="autosnippet"},
{
t("\\Sigma"),
}),
s({trig=";t", snippetType="autosnippet"},
{
t("\\tau"),
}),
s({trig=";f", snippetType="autosnippet"},
{
t("\\phi"),
}),
s({trig=";vf", snippetType="autosnippet"},
{
t("\\varphi"),
}),
s({trig=";F", snippetType="autosnippet"},
{
t("\\Phi"),
}),
s({trig=";c", snippetType="autosnippet"},
{
t("\\chi"),
}),
s({trig=";p", snippetType="autosnippet"},
{
t("\\psi"),
}),
s({trig=";P", snippetType="autosnippet"},
{
t("\\Psi"),
}),
s({trig=";w", snippetType="autosnippet"},
{
t("\\omega"),
}),
s({trig=";W", snippetType="autosnippet"},
{
t("\\Omega"),
}),
}

19
LuaSnip/tex/luatex.lua Normal file
View file

@ -0,0 +1,19 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
-- Return snippet tables
return
{
-- tex.sprint
s({trig = "tpp", snippetType="autosnippet"},
fmta(
[[
tex.sprint(<>)
]],
{
d(1, get_visual),
}
)
),
}

542
LuaSnip/tex/math.lua Normal file
View file

@ -0,0 +1,542 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
-- Math context detection
local tex = {}
tex.in_mathzone = function() return vim.fn['vimtex#syntax#in_mathzone']() == 1 end
tex.in_text = function() return not tex.in_mathzone() end
-- Return snippet tables
return
{
-- SUPERSCRIPT
s({trig = "([%w%)%]%}])'", wordTrig=false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- SUBSCRIPT
s({trig = "([%w%)%]%}]);", wordTrig=false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- SUBSCRIPT AND SUPERSCRIPT
s({trig = "([%w%)%]%}])__", wordTrig=false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>^{<>}_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2),
}
),
{condition = tex.in_mathzone}
),
-- TEXT SUBSCRIPT
s({trig = 'sd', snippetType="autosnippet", wordTrig=false},
fmta("_{\\mathrm{<>}}",
{ d(1, get_visual) }
),
{condition = tex.in_mathzone}
),
-- SUPERSCRIPT SHORTCUT
-- Places the first alphanumeric character after the trigger into a superscript.
s({trig = '([%w%)%]%}])"([%w])', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
f( function(_, snip) return snip.captures[2] end ),
}
),
{condition = tex.in_mathzone}
),
-- SUBSCRIPT SHORTCUT
-- Places the first alphanumeric character after the trigger into a subscript.
s({trig = '([%w%)%]%}]):([%w])', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
f( function(_, snip) return snip.captures[2] end ),
}
),
{condition = tex.in_mathzone}
),
-- EULER'S NUMBER SUPERSCRIPT SHORTCUT
s({trig = '([^%a])ee', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>e^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual)
}
),
{condition = tex.in_mathzone}
),
-- ZERO SUBSCRIPT SHORTCUT
s({trig = '([%a%)%]%}])00', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
t("0")
}
),
{condition = tex.in_mathzone}
),
-- MINUS ONE SUPERSCRIPT SHORTCUT
s({trig = '([%a%)%]%}])11', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
t("-1")
}
),
{condition = tex.in_mathzone}
),
-- J SUBSCRIPT SHORTCUT (since jk triggers snippet jump forward)
s({trig = '([%a%)%]%}])JJ', wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
t("j")
}
),
{condition = tex.in_mathzone}
),
-- PLUS SUPERSCRIPT SHORTCUT
s({trig = '([%a%)%]%}])%+%+', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
t("+")
}
),
{condition = tex.in_mathzone}
),
-- COMPLEMENT SUPERSCRIPT
s({trig = '([%a%)%]%}])CC', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
t("\\complement")
}
),
{condition = tex.in_mathzone}
),
-- CONJUGATE (STAR) SUPERSCRIPT SHORTCUT
s({trig = '([%a%)%]%}])%*%*', regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
t("*")
}
),
{condition = tex.in_mathzone}
),
-- VECTOR, i.e. \vec
s({trig = "([^%a])vv", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\vec{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- DEFAULT UNIT VECTOR WITH SUBSCRIPT, i.e. \unitvector_{}
s({trig = "([^%a])ue", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\unitvector_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- UNIT VECTOR WITH HAT, i.e. \uvec{}
s({trig = "([^%a])uv", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\uvec{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- MATRIX, i.e. \vec
s({trig = "([^%a])mt", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\mat{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- FRACTION
s({trig = "([^%a])ff", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\frac{<>}{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
i(2),
}
),
{condition = tex.in_mathzone}
),
-- ANGLE
s({trig = "([^%a])gg", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\ang{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- ABSOLUTE VALUE
s({trig = "([^%a])aa", regTrig = true, wordTrig = false, snippetType="autosnippet"},
fmta(
"<>\\abs{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- SQUARE ROOT
s({trig = "([^%\\])sq", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\sqrt{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- BINOMIAL SYMBOL
s({trig = "([^%\\])bnn", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\binom{<>}{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2),
}
),
{condition = tex.in_mathzone}
),
-- LOGARITHM WITH BASE SUBSCRIPT
s({trig = "([^%a%\\])ll", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\log_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
}
),
{condition = tex.in_mathzone}
),
-- DERIVATIVE with denominator only
s({trig = "([^%a])dV", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\dvOne{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- DERIVATIVE with numerator and denominator
s({trig = "([^%a])dvv", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\dv{<>}{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2)
}
),
{condition = tex.in_mathzone}
),
-- DERIVATIVE with numerator, denominator, and higher-order argument
s({trig = "([^%a])ddv", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\dvN{<>}{<>}{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2),
i(3),
}
),
{condition = tex.in_mathzone}
),
-- PARTIAL DERIVATIVE with denominator only
s({trig = "([^%a])pV", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\pdvOne{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual),
}
),
{condition = tex.in_mathzone}
),
-- PARTIAL DERIVATIVE with numerator and denominator
s({trig = "([^%a])pvv", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\pdv{<>}{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2)
}
),
{condition = tex.in_mathzone}
),
-- PARTIAL DERIVATIVE with numerator, denominator, and higher-order argument
s({trig = "([^%a])ppv", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\pdvN{<>}{<>}{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2),
i(3),
}
),
{condition = tex.in_mathzone}
),
-- SUM with lower limit
s({trig = "([^%a])sM", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\sum_{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
}
),
{condition = tex.in_mathzone}
),
-- SUM with upper and lower limit
s({trig = "([^%a])smm", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\sum_{<>}^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2),
}
),
{condition = tex.in_mathzone}
),
-- INTEGRAL with upper and lower limit
s({trig = "([^%a])intt", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\int_{<>}^{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
i(1),
i(2),
}
),
{condition = tex.in_mathzone}
),
-- INTEGRAL from positive to negative infinity
s({trig = "([^%a])intf", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\int_{\\infty}^{\\infty}",
{
f( function(_, snip) return snip.captures[1] end ),
}
),
{condition = tex.in_mathzone}
),
-- BOXED command
s({trig = "([^%a])bb", wordTrig = false, regTrig = true, snippetType="autosnippet"},
fmta(
"<>\\boxed{<>}",
{
f( function(_, snip) return snip.captures[1] end ),
d(1, get_visual)
}
),
{condition = tex.in_mathzone}
),
--
-- BEGIN STATIC SNIPPETS
--
-- DIFFERENTIAL, i.e. \diff
s({trig = "df", snippetType="autosnippet", priority=2000, snippetType="autosnippet"},
{
t("\\diff"),
},
{condition = tex.in_mathzone}
),
-- BASIC INTEGRAL SYMBOL, i.e. \int
s({trig = "in1", snippetType="autosnippet"},
{
t("\\int"),
},
{condition = tex.in_mathzone}
),
-- DOUBLE INTEGRAL, i.e. \iint
s({trig = "in2", snippetType="autosnippet"},
{
t("\\iint"),
},
{condition = tex.in_mathzone}
),
-- TRIPLE INTEGRAL, i.e. \iiint
s({trig = "in3", snippetType="autosnippet"},
{
t("\\iiint"),
},
{condition = tex.in_mathzone}
),
-- CLOSED SINGLE INTEGRAL, i.e. \oint
s({trig = "oi1", snippetType="autosnippet"},
{
t("\\oint"),
},
{condition = tex.in_mathzone}
),
-- CLOSED DOUBLE INTEGRAL, i.e. \oiint
s({trig = "oi2", snippetType="autosnippet"},
{
t("\\oiint"),
},
{condition = tex.in_mathzone}
),
-- GRADIENT OPERATOR, i.e. \grad
s({trig = "gdd", snippetType="autosnippet"},
{
t("\\grad "),
},
{condition = tex.in_mathzone}
),
-- CURL OPERATOR, i.e. \curl
s({trig = "cll", snippetType="autosnippet"},
{
t("\\curl "),
},
{condition = tex.in_mathzone}
),
-- DIVERGENCE OPERATOR, i.e. \divergence
s({trig = "DI", snippetType="autosnippet"},
{
t("\\div "),
},
{condition = tex.in_mathzone}
),
-- LAPLACIAN OPERATOR, i.e. \laplacian
s({trig = "laa", snippetType="autosnippet"},
{
t("\\laplacian "),
},
{condition = tex.in_mathzone}
),
-- PARALLEL SYMBOL, i.e. \parallel
s({trig = "||", snippetType="autosnippet"},
{
t("\\parallel"),
}
),
-- CDOTS, i.e. \cdots
s({trig = "cdd", snippetType="autosnippet"},
{
t("\\cdots"),
}
),
-- LDOTS, i.e. \ldots
s({trig = "ldd", snippetType="autosnippet"},
{
t("\\ldots"),
}
),
-- EQUIV, i.e. \equiv
s({trig = "eqq", snippetType="autosnippet"},
{
t("\\equiv "),
}
),
-- SETMINUS, i.e. \setminus
s({trig = "stm", snippetType="autosnippet"},
{
t("\\setminus "),
}
),
-- SUBSET, i.e. \subset
s({trig = "sbb", snippetType="autosnippet"},
{
t("\\subset "),
}
),
-- APPROX, i.e. \approx
s({trig = "px", snippetType="autosnippet"},
{
t("\\approx "),
},
{condition = tex.in_mathzone}
),
-- PROPTO, i.e. \propto
s({trig = "pt", snippetType="autosnippet"},
{
t("\\propto "),
},
{condition = tex.in_mathzone}
),
-- COLON, i.e. \colon
s({trig = "::", snippetType="autosnippet"},
{
t("\\colon "),
}
),
-- IMPLIES, i.e. \implies
s({trig = ">>", snippetType="autosnippet"},
{
t("\\implies "),
}
),
-- DOT PRODUCT, i.e. \cdot
s({trig = ",.", snippetType="autosnippet"},
{
t("\\cdot "),
}
),
-- CROSS PRODUCT, i.e. \times
s({trig = "xx", snippetType="autosnippet"},
{
t("\\times "),
}
),
}

84
LuaSnip/tex/static.lua Normal file
View file

@ -0,0 +1,84 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
-- Environment/syntax context detection
local tex = {}
tex.in_mathzone = function() return vim.fn['vimtex#syntax#in_mathzone']() == 1 end
tex.in_text = function() return not tex.in_mathzone() end
tex.in_tikz = function()
local is_inside = vim.fn['vimtex#env#is_inside']("tikzpicture")
return (is_inside[1] > 0 and is_inside[2] > 0)
end
-- Return snippet tables
return
{
s({trig="q"},
{
t("\\quad "),
}
),
s({trig="qq", snippetType="autosnippet"},
{
t("\\qquad "),
}
),
s({trig="npp", snippetType="autosnippet"},
{
t({"\\newpage", ""}),
},
{condition = line_begin}
),
s({trig="which", snippetType="autosnippet"},
{
t("\\text{ for which } "),
},
{condition = tex.in_mathzone}
),
s({trig="all", snippetType="autosnippet"},
{
t("\\text{ for all } "),
},
{condition = tex.in_mathzone}
),
s({trig="and", snippetType="autosnippet"},
{
t("\\quad \\text{and} \\quad"),
},
{condition = tex.in_mathzone}
),
s({trig="forall", snippetType="autosnippet"},
{
t("\\text{ for all } "),
},
{condition = tex.in_mathzone}
),
s({trig = "toc", snippetType="autosnippet"},
{
t("\\tableofcontents"),
},
{ condition = line_begin }
),
s({trig="inff", snippetType="autosnippet"},
{
t("\\infty"),
}
),
s({trig="ii", snippetType="autosnippet"},
{
t("\\item "),
},
{ condition = line_begin }
),
s({trig = "--", snippetType="autosnippet"},
{t('% --------------------------------------------- %')},
{condition = line_begin}
),
-- HLINE WITH EXTRA VERTICAL SPACE
s({trig = "hl"},
{t('\\hline {\\rule{0pt}{2.5ex}} \\hspace{-7pt}')},
{condition = line_begin}
),
}

206
LuaSnip/tex/system.lua Normal file
View file

@ -0,0 +1,206 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
-- Math context detection
local tex = {}
tex.in_mathzone = function() return vim.fn['vimtex#syntax#in_mathzone']() == 1 end
tex.in_text = function() return not tex.in_mathzone() end
-- Return snippet tables
return
{
-- ANNOTATE (custom command for annotating equation derivations)
s({trig = "ann", snippetType="autosnippet"},
fmta(
[[
\annotate{<>}{<>}
]],
{
i(1),
d(2, get_visual),
}
)
),
-- REFERENCE
s({trig = " RR", snippetType="autosnippet", wordTrig=false},
fmta(
[[
~\ref{<>}
]],
{
d(1, get_visual),
}
)
),
-- DOCUMENTCLASS
s({trig = "dcc", snippetType="autosnippet"},
fmta(
[=[
\documentclass[<>]{<>}
]=],
{
i(1, "a4paper"),
i(2, "article"),
}
),
{ condition = line_begin }
),
-- USE A LATEX PACKAGE
s({trig = "pack", snippetType="autosnippet"},
fmta(
[[
\usepackage{<>}
]],
{
d(1, get_visual),
}
),
{ condition = line_begin }
),
-- INPUT a LaTeX file
s({trig = "inn", snippetType="autosnippet"},
fmta(
[[
\input{<><>}
]],
{
i(1, "~/dotfiles/config/latex/templates/"),
i(2)
}
),
{ condition = line_begin }
),
-- LABEL
s({trig = "lbl", snippetType="autosnippet"},
fmta(
[[
\label{<>}
]],
{
d(1, get_visual),
}
)
),
-- HPHANTOM
s({trig = "hpp", snippetType="autosnippet"},
fmta(
[[
\hphantom{<>}
]],
{
d(1, get_visual),
}
)
),
s({trig = "TODOO", snippetType="autosnippet"},
fmta(
[[\TODO{<>}]],
{
d(1, get_visual),
}
)
),
s({trig="nc"},
fmta(
[[\newcommand{<>}{<>}]],
{
i(1),
i(2)
}
),
{condition = line_begin}
),
s({trig="sii", snippetType="autosnippet"},
fmta(
[[\si{<>}]],
{
i(1),
}
)
),
s({trig="SI"},
fmta(
[[\SI{<>}{<>}]],
{
i(1),
i(2)
}
)
),
-- URL
s({trig="url"},
fmta(
[[\url{<>}]],
{
d(1, get_visual),
}
)
),
-- href command with URL in visual selection
s({trig="LU", snippetType="autosnippet"},
fmta(
[[\href{<>}{<>}]],
{
d(1, get_visual),
i(2)
}
)
),
-- href command with text in visual selection
s({trig="LL", snippetType="autosnippet"},
fmta(
[[\href{<>}{<>}]],
{
i(1),
d(2, get_visual)
}
)
),
-- HSPACE
s({trig="hss", snippetType="autosnippet"},
fmta(
[[\hspace{<>}]],
{
d(1, get_visual),
}
)
),
-- VSPACE
s({trig="vss", snippetType="autosnippet"},
fmta(
[[\vspace{<>}]],
{
d(1, get_visual),
}
)
),
-- SECTION
s({trig="h1", snippetType="autosnippet"},
fmta(
[[\section{<>}]],
{
d(1, get_visual),
}
)
),
-- SUBSECTION
s({trig="h2", snippetType="autosnippet"},
fmta(
[[\subsection{<>}]],
{
d(1, get_visual),
}
)
),
-- SUBSUBSECTION
s({trig="h3", snippetType="autosnippet"},
fmta(
[[\subsubsection{<>}]],
{
d(1, get_visual),
}
)
),
}

81
LuaSnip/tex/tmp.lua Normal file
View file

@ -0,0 +1,81 @@
local helpers = require('personal.luasnip-helper-funcs')
local get_visual = helpers.get_visual
local line_begin = require("luasnip.extras.expand_conditions").line_begin
-- Math context detection
local tex = {}
tex.in_mathzone = function() return vim.fn['vimtex#syntax#in_mathzone']() == 1 end
tex.in_text = function() return not tex.in_mathzone() end
return {
-- Equation, choice for labels
s({trig="beq", dscr="Expands 'beq' into an equation environment, with a choice for labels", snippetType="autosnippet"},
fmta(
[[
\begin{equation}<>
<>
\end{equation}
]],
{ c(1,
{
sn(2, -- Choose to specify an equation label
{
t("\\label{eq:"),
i(1),
t("}"),
}
),
t([[]]), -- Choose no label
},
{}
),
i(2) }
)
),
-- Figure environment
s({trig="foofig", dscr="Use 'fig' for figure environmennt, with options"},
fmta(
[[
\begin{figure}<>
\centering
\includegraphics<>{<>}
\caption{<>}
\label{fig:<>}
\end{figure}
]],
{
-- Optional [htbp] field
c(1,
{
t([[]]), -- Choice 1, empty
t("[htbp]"), -- Choice 2, this may be turned into a snippet
},
{}
),
-- Options for includegraphics
c(2,
{
t([[]]), -- Choice 1, empty
sn(3, -- Choice 2, this may be turned into a snippet
{
t("[width="),
i(1),
t("\\textwidth]"),
}
),
},
{}
),
i(3, "filename"),
i(4, "text"),
i(5, "label"),
}
),
{condition = line_begin}
),
}