Updated vimtex and snippets
This commit is contained in:
parent
84a6b218fe
commit
10bf23a6ec
|
@ -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) }
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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 }
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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) }
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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 }
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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) }
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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
|
||||
]],
|
||||
{}
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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}
|
||||
),
|
||||
}
|
||||
|
|
@ -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:
|
||||
]],
|
||||
{ }
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
||||
|
|
@ -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}
|
||||
),
|
||||
}
|
||||
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -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),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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 }
|
||||
),
|
||||
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
||||
|
||||
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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
|
|
@ -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),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
|
|
@ -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 }
|
||||
),
|
||||
}
|
|
@ -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 }
|
||||
),
|
||||
}
|
|
@ -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"),
|
||||
}),
|
||||
}
|
|
@ -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),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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 "),
|
||||
}
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
}
|
|
@ -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),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
|
@ -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}
|
||||
),
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
-- -- Only load this plugin if it has not yet been loaded for this buffer
|
||||
-- if vim.b.did_myvimtexsettings then
|
||||
-- return
|
||||
-- end
|
||||
-- vim.b.did_myvimtexsettings = true
|
||||
|
||||
-- vim.api.nvim_set_keymap('n', '<leader>li', '<plug>(vimtex-info)', {desc = "Vimtex Info"})
|
||||
-- vim.api.nvim_set_keymap('n', '<leader>ls', ':VimtexTocToggle<CR>', {desc = "Table Of Content Toggle"})
|
||||
-- vim.api.nvim_set_keymap('n', '<leader>lv', ':VimtexView<CR>', {desc = "View in Viwer"})
|
||||
|
||||
-- Toggle shell escape on and off when using minted package
|
||||
local function TexToggleShellEscape()
|
||||
local options = vim.g.vimtex_compiler_latexmk.options
|
||||
local shell_escape_index = vim.fn.index(options, '-shell-escape')
|
||||
if shell_escape_index ~= -1 then
|
||||
table.remove(options, shell_escape_index)
|
||||
else
|
||||
table.insert(options, 1, '-shell-escape')
|
||||
end
|
||||
vim.fn['VimtexReload']()
|
||||
vim.fn['VimtexClean']()
|
||||
end
|
||||
|
||||
vim.api.nvim_set_keymap('n', '<leader>le', '<cmd>lua TexToggleShellEscape()<CR>', {desc = "Toggle Shell Escape"})
|
||||
|
||||
-- When loading new buffers, search for references to minted package in the
|
||||
-- document preamble and enable shell escape if minted is detected.
|
||||
local preamble_output = vim.fn.systemlist('head -n 20 ' .. vim.fn.expand('%') .. ' | grep "minted"')
|
||||
if #preamble_output > 0 then
|
||||
table.insert(vim.g.vimtex_compiler_latexmk.options, 1, '-shell-escape')
|
||||
end
|
||||
|
||||
-- Close viewers when VimTeX buffers are closed
|
||||
local function CloseViewers()
|
||||
if vim.fn.executable('xdotool') == 1 and vim.b.vimtex_viewer_xwin_id > 0 then
|
||||
vim.fn.system('xdotool windowclose ' .. vim.b.vimtex_viewer_xwin_id)
|
||||
end
|
||||
end
|
||||
|
||||
vim.cmd('augroup vimtex_event_close')
|
||||
vim.cmd('au!')
|
||||
vim.cmd('au User VimtexEventQuit call CloseViewers()')
|
||||
vim.cmd('augroup END')
|
||||
|
||||
-- -- Define mappings
|
||||
-- vim.api.nvim_set_keymap('n', 'dse', '<plug>(vimtex-env-delete)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'dsc', '<plug>(vimtex-cmd-delete)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'dsm', '<plug>(vimtex-env-delete-math)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'dsd', '<plug>(vimtex-delim-delete)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'cse', '<plug>(vimtex-env-change)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'csc', '<plug>(vimtex-cmd-change)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'csm', '<plug>(vimtex-env-change-math)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'csd', '<plug>(vimtex-delim-change-math)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'tsf', '<plug>(vimtex-cmd-toggle-frac)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'tsc', '<plug>(vimtex-cmd-toggle-star)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'tse', '<plug>(vimtex-env-toggle-star)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'tsd', '<plug>(vimtex-delim-toggle-modifier)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'tsD', '<plug>(vimtex-delim-toggle-modifier-reverse)', {})
|
||||
-- vim.api.nvim_set_keymap('n', 'tsm', '<plug>(vimtex-env-toggle-math)', {})
|
||||
-- vim.api.nvim_set_keymap('i', ']]', '<plug>(vimtex-delim-close)', {})
|
||||
|
||||
-- -- Text objects in operator-pending mode
|
||||
-- vim.api.nvim_set_keymap('o', 'ac', '<plug>(vimtex-ac)', {})
|
||||
-- vim.api.nvim_set_keymap('x', 'ac', '<plug>(vimtex-ac)', {})
|
||||
-- vim.api.nvim_set_keymap('o', 'ic', '<plug>(vimtex-ic)', {})
|
||||
-- vim.api.nvim_set_keymap('x', 'ic', '<plug>(vimtex-ic)', {})
|
||||
|
||||
-- -- Define more mappings as needed...
|
184
init.lua
184
init.lua
|
@ -44,6 +44,18 @@ P.S. You can delete this when you're done too. It's your config now :)
|
|||
vim.g.mapleader = ' '
|
||||
vim.g.maplocalleader = ' '
|
||||
|
||||
-- OS detection
|
||||
if vim.fn.exists("g:os_current") == 0 then
|
||||
if vim.fn.system('uname -s') == "Linux\n" then
|
||||
vim.g.os_current = "Linux"
|
||||
elseif vim.fn.system('uname -s') == "Darwin\n" then
|
||||
vim.g.os_current = "Darwin"
|
||||
else
|
||||
print("Error: the current operating system won't support all of my Vim configurations.")
|
||||
vim.g.os_current = "Other"
|
||||
end
|
||||
end
|
||||
|
||||
-- [[ Install `lazy.nvim` plugin manager ]]
|
||||
-- https://github.com/folke/lazy.nvim
|
||||
-- `:help lazy.nvim.txt` for more info
|
||||
|
@ -106,9 +118,8 @@ require('lazy').setup({
|
|||
-- Adds LSP completion capabilities
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
'hrsh7th/cmp-path',
|
||||
|
||||
-- Adds a number of user-friendly snippets
|
||||
'rafamadriz/friendly-snippets',
|
||||
'hrsh7th/cmp-buffer',
|
||||
-- 'minhaz5000/friendly-snippets',
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -205,7 +216,7 @@ require('lazy').setup({
|
|||
opts = {
|
||||
options = {
|
||||
icons_enabled = false,
|
||||
theme = 'onedark',
|
||||
theme = 'auto',
|
||||
component_separators = '|',
|
||||
section_separators = '',
|
||||
},
|
||||
|
@ -278,6 +289,7 @@ vim.o.hlsearch = false
|
|||
|
||||
-- Make line numbers default
|
||||
vim.wo.number = true
|
||||
vim.wo.relativenumber = true
|
||||
|
||||
-- Enable mouse mode
|
||||
vim.o.mouse = 'a'
|
||||
|
@ -290,6 +302,19 @@ vim.o.clipboard = 'unnamedplus'
|
|||
-- Enable break indent
|
||||
vim.o.breakindent = true
|
||||
|
||||
-- Enable expandtab to insert spaces instead of tabs
|
||||
vim.opt.expandtab = true
|
||||
|
||||
-- Set the width of a tab character to 4 spaces
|
||||
vim.opt.tabstop = 4
|
||||
|
||||
-- Set the number of spaces used for each step of (auto)indent
|
||||
vim.opt.shiftwidth = 4
|
||||
|
||||
-- Enable smarttab to insert a combination of spaces and tabs intelligently
|
||||
vim.opt.smarttab = true
|
||||
|
||||
|
||||
-- Save undo history
|
||||
vim.o.undofile = true
|
||||
|
||||
|
@ -316,6 +341,20 @@ vim.o.termguicolors = true
|
|||
-- See `:help vim.keymap.set()`
|
||||
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
|
||||
|
||||
-- Move current line up and down
|
||||
vim.keymap.set('n', '<M-j>', ':m .+1<CR>==', { noremap = true, silent = true })
|
||||
vim.keymap.set('n', '<M-k>', ':m .-2<CR>==', { noremap = true, silent = true })
|
||||
|
||||
-- Move selected lines up and down
|
||||
vim.keymap.set('x', '<M-j>', ':move \'>+<CR>gv=gv', { noremap = true, silent = true })
|
||||
vim.keymap.set('x', '<M-k>', ':move \'<-2<CR>gv=gv', { noremap = true, silent = true })
|
||||
|
||||
-- easy save file
|
||||
vim.keymap.set('n', '<C-s>', ':w<CR>')
|
||||
|
||||
-- use U for redo :))
|
||||
vim.keymap.set('n', 'U', '<C-r>', {})
|
||||
|
||||
-- Remap for dealing with word wrap
|
||||
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
||||
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
||||
|
@ -520,7 +559,7 @@ local on_attach = function(_, bufnr)
|
|||
|
||||
-- See `:help K` for why this keymap
|
||||
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
||||
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||
nmap('<C-i>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||
|
||||
-- Lesser used LSP functionality
|
||||
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||
|
@ -613,9 +652,67 @@ mason_lspconfig.setup_handlers {
|
|||
-- [[ Configure nvim-cmp ]]
|
||||
-- See `:help cmp`
|
||||
local cmp = require 'cmp'
|
||||
local luasnip = require 'luasnip'
|
||||
require('luasnip.loaders.from_vscode').lazy_load()
|
||||
luasnip.config.setup {}
|
||||
local luasnip = require "luasnip"
|
||||
local types = require "luasnip.util.types"
|
||||
|
||||
require("luasnip.loaders.from_lua").lazy_load({paths = "~/.config/nvim/LuaSnip/"})
|
||||
-- require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
vim.keymap.set('', '<Leader>U', '<Cmd>lua require("luasnip.loaders.from_lua").lazy_load({paths = "~/.config/nvim/LuaSnip/"})<CR><Cmd>echo "Snippets refreshed!"<CR>', { desc = "[U]pdate Snippets"})
|
||||
|
||||
luasnip.config.setup({
|
||||
-- Allow autotrigger snippets
|
||||
enable_autosnippets = true,
|
||||
-- This one is cool cause if you have dynamic snippets, it updates as you type!
|
||||
updateevents = "TextChanged,TextChangedI",
|
||||
-- For equivalent of UltiSnips visual selection
|
||||
store_selection_keys = "<Tab>",
|
||||
-- Event on which to check for exiting a snippet's region
|
||||
region_check_events = 'InsertEnter',
|
||||
delete_check_events = 'InsertLeave',
|
||||
ext_opts = {
|
||||
[types.choiceNode] = {
|
||||
active = {
|
||||
virt_text = { { " « ", "NonTest" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
vim.keymap.set({ "i", "s" }, "<c-j>", function()
|
||||
if luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
end
|
||||
end, { silent = true })
|
||||
|
||||
vim.keymap.set({ "i", "s" }, "<c-k>", function()
|
||||
if luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
end
|
||||
end, { silent = true })
|
||||
|
||||
-- <c-l> is selecting within a list of options.
|
||||
-- This is useful for choice nodes (introduced in the forthcoming episode 2)
|
||||
vim.keymap.set("i", "<c-f>", function()
|
||||
if luasnip.choice_active() then
|
||||
luasnip.change_choice(1)
|
||||
end
|
||||
end)
|
||||
|
||||
vim.keymap.set("i", "<c-u>", require "luasnip.extras.select_choice")
|
||||
|
||||
-- local auto_expand = require("luasnip").expand_auto
|
||||
-- luasnip.expand_auto = function(...)
|
||||
-- vim.o.undolevels = vim.o.undolevels
|
||||
-- auto_expand(...)
|
||||
-- end
|
||||
|
||||
local has_words_before = function()
|
||||
unpack = unpack or table.unpack
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
|
||||
cmp.setup {
|
||||
snippet = {
|
||||
|
@ -627,20 +724,57 @@ cmp.setup {
|
|||
completeopt = 'menu,menuone,noinsert',
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert {
|
||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete {},
|
||||
['<CR>'] = cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
|
||||
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
|
||||
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<c-y>"] = cmp.mapping(
|
||||
cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Insert,
|
||||
select = true,
|
||||
},
|
||||
{ "i", "c" }
|
||||
),
|
||||
["<M-y>"] = cmp.mapping(
|
||||
cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = false,
|
||||
},
|
||||
{ "i", "c" }
|
||||
),
|
||||
|
||||
["<C-Space>"] = cmp.mapping {
|
||||
i = cmp.mapping.complete(),
|
||||
c = function(
|
||||
_ --[[fallback]]
|
||||
)
|
||||
if cmp.visible() then
|
||||
if not cmp.confirm { select = true } then
|
||||
return
|
||||
end
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
["<c-q>"] = cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = false,
|
||||
},
|
||||
|
||||
-- -- ["<tab>"] = false,
|
||||
-- ["<tab>"] = cmp.config.disable,
|
||||
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
if #cmp.get_entries() == 1 then
|
||||
cmp.confirm({ select = true })
|
||||
else
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
end
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
|
@ -648,17 +782,27 @@ cmp.setup {
|
|||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
|
||||
-- ['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
-- ['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
-- ['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
-- ['<C-Space>'] = cmp.mapping.complete {},
|
||||
-- ['<CR>'] = cmp.mapping.confirm {
|
||||
-- behavior = cmp.ConfirmBehavior.Replace,
|
||||
-- select = true,
|
||||
-- },
|
||||
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'path' },
|
||||
{ name = "buffer", keyword_length = 5 },
|
||||
{ name = "path" },
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +1,33 @@
|
|||
{
|
||||
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
|
||||
"LuaSnip": { "branch": "master", "commit": "82108e7e31cc6fc223cc5df5cae6d89f70bb199f" },
|
||||
"LuaSnip": { "branch": "master", "commit": "f3b3d3446bcbfa62d638b1903ff00a78b2b730a1" },
|
||||
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
|
||||
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
|
||||
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
|
||||
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
|
||||
"fidget.nvim": { "branch": "main", "commit": "3a93300c076109d86c7ce35ec67a8034ae6ba9db" },
|
||||
"friendly-snippets": { "branch": "main", "commit": "69a2c1675b66e002799f5eef803b87a12f593049" },
|
||||
"gitsigns.nvim": { "branch": "main", "commit": "3e6e91b09f0468c32d3b96dcacf4b947f037ce25" },
|
||||
"indent-blankline.nvim": { "branch": "master", "commit": "12e92044d313c54c438bd786d11684c88f6f78cd" },
|
||||
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
|
||||
"lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "0989bdf4fdf7b5aa4c74131d7ffccc3f399ac788" },
|
||||
"mason.nvim": { "branch": "main", "commit": "e110bc3be1a7309617cecd77bfe4bf86ba1b8134" },
|
||||
"neo-tree.nvim": { "branch": "main", "commit": "77d9f484b88fd380386b46ed9206e5374d69d9d8" },
|
||||
"neodev.nvim": { "branch": "main", "commit": "dde00106b9094f101980b364fae02fd85d357306" },
|
||||
"nui.nvim": { "branch": "main", "commit": "35da9ca1de0fc4dda96c2e214d93d363c145f418" },
|
||||
"nvim-autopairs": { "branch": "master", "commit": "9fd41181693dd4106b3e414a822bb6569924de81" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "c5c8d4ca6c0ef26a44b23da7f0228cc3808be81c" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "8cd2b230174efbf7b5d9f49fe2f90bda6b5eb16e" },
|
||||
"nvim-treesitter-textobjects": { "branch": "master", "commit": "85b9d0cbd4ff901abcda862b50dbb34e0901848b" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "db0c864375c198cacc171ff373e76bfce2a85045" },
|
||||
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
|
||||
"fidget.nvim": { "branch": "main", "commit": "60404ba67044c6ab01894dd5bf77bd64ea5e09aa" },
|
||||
"gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" },
|
||||
"indent-blankline.nvim": { "branch": "master", "commit": "821a7acd88587d966f7e464b0b3031dfe7f5680c" },
|
||||
"lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" },
|
||||
"lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" },
|
||||
"mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" },
|
||||
"neo-tree.nvim": { "branch": "main", "commit": "f3941c57ec85d7bdb44fa53fd858fd80f159018f" },
|
||||
"neodev.nvim": { "branch": "main", "commit": "84e0290f5600e8b89c0dfcafc864f45496a53400" },
|
||||
"nui.nvim": { "branch": "main", "commit": "b81333d12f824dbed5eb231c8a4409a290fdd848" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "9553725789be682ecd945a527ec552e489ea8534" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "a47540fd737eb5c03ee21ee69eb8134ce5568fb6" },
|
||||
"nvim-treesitter-textobjects": { "branch": "master", "commit": "95933e762e28f9d38b572d65e7e4da9d2f4d90cb" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "4adea17610d140a99c313e3f79a9dc01825d59ae" },
|
||||
"plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" },
|
||||
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" },
|
||||
"telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
|
||||
"toggleterm.nvim": { "branch": "main", "commit": "cbd041d91b90cd3c02df03fe6133208888f8e008" },
|
||||
"tokyonight.nvim": { "branch": "main", "commit": "f247ee700b569ed43f39320413a13ba9b0aef0db" },
|
||||
"vim-fugitive": { "branch": "master", "commit": "59659093581aad2afacedc81f009ed6a4bfad275" },
|
||||
"toggleterm.nvim": { "branch": "main", "commit": "193786e0371e3286d3bc9aa0079da1cd41beaa62" },
|
||||
"tokyonight.nvim": { "branch": "main", "commit": "610179f7f12db3d08540b6cc61434db2eaecbcff" },
|
||||
"vim-fugitive": { "branch": "master", "commit": "2e88f14a585c014691904ba8fe39e6ea851c9422" },
|
||||
"vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" },
|
||||
"vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" },
|
||||
"vimtex": { "branch": "master", "commit": "f9b19d09ee6f0ba70dad0b5c2e710dd700681000" },
|
||||
"vimtex": { "branch": "master", "commit": "2bb7cdc17c0ac18266e4c96083290956169c1c38" },
|
||||
"which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
-- File: lua/custom/plugins/autopairs.lua
|
||||
|
||||
return {
|
||||
"windwp/nvim-autopairs",
|
||||
-- Optional dependency
|
||||
dependencies = { 'hrsh7th/nvim-cmp' },
|
||||
config = function()
|
||||
require("nvim-autopairs").setup {}
|
||||
-- If you want to automatically add `(` after selecting a function or method
|
||||
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
||||
local cmp = require('cmp')
|
||||
cmp.event:on(
|
||||
'confirm_done',
|
||||
cmp_autopairs.on_confirm_done()
|
||||
)
|
||||
end,
|
||||
}
|
|
@ -25,5 +25,5 @@ return {
|
|||
}
|
||||
}
|
||||
end,
|
||||
vim.keymap.set('n', '<leader>ft', '<Cmd>Neotree toggle<CR>', {desc = "Open File Tree"})
|
||||
vim.keymap.set('n', '<C-t>', '<Cmd>Neotree toggle<CR>', { desc = "Open File Tree" })
|
||||
}
|
||||
|
|
|
@ -1,5 +1,47 @@
|
|||
return {
|
||||
'akinsho/toggleterm.nvim', version = "*", config = true,
|
||||
|
||||
vim.keymap.set('n', '<C-j>', '<Cmd>ToggleTerm<CR>')
|
||||
'akinsho/toggleterm.nvim',
|
||||
version = "*",
|
||||
config = function()
|
||||
require("toggleterm").setup {
|
||||
size = 20,
|
||||
open_mapping = [[<c-\>]],
|
||||
hide_numbers = true,
|
||||
shade_filetypes = {},
|
||||
shade_terminals = true,
|
||||
shading_factor = 2,
|
||||
start_in_insert = true,
|
||||
insert_mappings = true,
|
||||
persist_size = true,
|
||||
direction = "float",
|
||||
auto_scroll = true,
|
||||
close_on_exit = true,
|
||||
shell = vim.o.shell,
|
||||
float_opts = {
|
||||
border = "curved",
|
||||
winblend = 0,
|
||||
highlights = {
|
||||
border = "Normal",
|
||||
background = "Normal",
|
||||
},
|
||||
},
|
||||
}
|
||||
function _G.set_terminal_keymaps()
|
||||
local opts = { buffer = 0 }
|
||||
vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
|
||||
vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
|
||||
vim.keymap.set('t', '<C-[>', [[<Cmd>wincmd h<CR>]], opts)
|
||||
-- vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
|
||||
-- vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
|
||||
vim.keymap.set('t', '<C-]>', [[<Cmd>wincmd l<CR>]], opts)
|
||||
-- vim.keymap.set('t', '<C-w>', [[<C-\><C-n><C-w>]], opts)
|
||||
|
||||
|
||||
-- vim.keymap.set('n', '<Leader>tt', '<Cmd>ToggleTerm<CR>')
|
||||
-- vim.keymap.set('n', '<Leader>t1', '<Cmd>1ToggleTerm<CR>')
|
||||
-- vim.keymap.set('n', '<Leader>t2', '<Cmd>2ToggleTerm<CR>')
|
||||
end
|
||||
|
||||
-- if you only want these mappings for toggle term use term://*toggleterm#* instead
|
||||
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
|
||||
end
|
||||
}
|
||||
|
|
|
@ -8,22 +8,62 @@ return {
|
|||
build_dir = 'build',
|
||||
executable = 'latexmk',
|
||||
options = {
|
||||
'-pdf',
|
||||
'-pdflua',
|
||||
'-interaction=nonstopmode',
|
||||
'-synctex=1',
|
||||
'-file-line-error',
|
||||
'-verbose',
|
||||
},
|
||||
}
|
||||
|
||||
-- Enable automatic compilation on save
|
||||
vim.g.vimtex_autocompile = {
|
||||
callback = 1,
|
||||
continuous = 1,
|
||||
on_insert_leave = 1,
|
||||
}
|
||||
|
||||
-- Turn off VimTeX indentation
|
||||
-- vim.g.vimtex_indent_enabled = 0
|
||||
|
||||
-- Disable default mappings; I'll define my own
|
||||
-- vim.g.vimtex_mappings_enabled = 0
|
||||
|
||||
-- Disable insert mode mappings (in favor of a dedicated snippet engine)
|
||||
-- vim.g.vimtex_imaps_enabled = 0
|
||||
|
||||
-- Disable syntax conceal
|
||||
vim.g.vimtex_syntax_conceal_disable = 0
|
||||
|
||||
-- Default is 500 lines and gave me lags on missed key presses
|
||||
vim.g.vimtex_delim_stopline = 50
|
||||
|
||||
-- VimTeX toggle delimeter configuration
|
||||
vim.g.vimtex_delim_toggle_mod_list = {
|
||||
{'\\left', '\\right'},
|
||||
{'\\big', '\\big'},
|
||||
}
|
||||
|
||||
-- Don't open quickfix for warning messages if no errors are present
|
||||
vim.g.vimtex_quickfix_open_on_warning = 0
|
||||
|
||||
--Disable some compilation warning messages
|
||||
vim.g.vimtex_quickfix_ignore_filters = {
|
||||
'LaTeX hooks Warning',
|
||||
'Underfull \\hbox',
|
||||
'Overfull \\hbox',
|
||||
'LaTeX Warning: .+ float specifier changed to',
|
||||
'Package siunitx Warning: Detected the "physics" package:',
|
||||
'Package hyperref Warning: Token not allowed in a PDF string',
|
||||
'Fatal error occurred, no output PDF file produced!',
|
||||
}
|
||||
|
||||
-- Enable PDF preview using your favorite PDF viewer
|
||||
vim.g.vimtex_view_method = 'zathura'
|
||||
vim.g.vimtex_view_method = 'zathura_simple'
|
||||
-- vim.g.vimtex_view_general_viewer = 'okular'
|
||||
-- vim.g.vimtex_view_general_options = '--unique file:@pdf\\#src:@line@tex'
|
||||
-- Define the VimtexHookZathura function
|
||||
|
||||
end,
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
local M = {}
|
||||
|
||||
local ls = require("luasnip")
|
||||
local sn = ls.snippet_node
|
||||
local i = ls.insert_node
|
||||
local s = ls.snippet
|
||||
local isn = ls.indent_snippet_node
|
||||
local t = ls.text_node
|
||||
local f = ls.function_node
|
||||
local c = ls.choice_node
|
||||
local d = ls.dynamic_node
|
||||
local r = ls.restore_node
|
||||
local events = require("luasnip.util.events")
|
||||
local ai = require("luasnip.nodes.absolute_indexer")
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
local m = require("luasnip.extras").m
|
||||
local lambda = require("luasnip.extras").l
|
||||
local postfix = require("luasnip.extras.postfix").postfix
|
||||
|
||||
ls.config.setup{
|
||||
-- Allow autotrigger snippets
|
||||
enable_autosnippets = true,
|
||||
-- For equivalent of UltiSnips visual selection
|
||||
store_selection_keys = "<Tab>",
|
||||
-- Event on which to check for exiting a snippet's region
|
||||
region_check_events = 'InsertEnter',
|
||||
delete_check_events = 'InsertLeave',
|
||||
}
|
||||
|
||||
function M.get_ISO_8601_date()
|
||||
return os.date("%Y-%m-%d")
|
||||
end
|
||||
|
||||
function M.get_visual(args, parent)
|
||||
if (#parent.snippet.env.LS_SELECT_RAW > 0) then
|
||||
return sn(nil, i(1, parent.snippet.env.LS_SELECT_RAW))
|
||||
else
|
||||
return sn(nil, i(1, ''))
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
|
@ -0,0 +1 @@
|
|||
Scripts for implementing inverse search between PDF files (generally LaTeX or `lilypond-book` output) and the corresponding text source files in the Neovim text editor.
|
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
# A script to manage inverse search from both LyTeX and LaTeX files
|
||||
# Arguments:
|
||||
# 1: line number to display
|
||||
# e.g. "42"
|
||||
# 2: path to LaTeX source file
|
||||
# e.g. "$HOME/test/tex/test.tex"
|
||||
# 3: operating system name as returned by uname
|
||||
# i.e. "Darwin" on macOS and "Linux" on Linux
|
||||
|
||||
# echo "${1}\n${2}" > "${HOME}/log.txt"
|
||||
|
||||
function inverse_search() {
|
||||
# Arguments:
|
||||
# 1: path to Neovim server socket
|
||||
# e.g. "/tmp/texsocket" or "/tmp/lytexsocket"
|
||||
# 2: line number to display
|
||||
# e.g. "42"
|
||||
# 3: path to the file to display
|
||||
# e.g. /Users/ejmastnak/test/tex/test.tex
|
||||
# 4: operating system name as returned by uname
|
||||
# i.e. "Darwin" on macOS and "Linux" on Linux
|
||||
if [ ${4} = "Darwin" ] # macOS
|
||||
then
|
||||
nvr --servername="${1}" +"${2}" "${3}" && open -a Alacritty
|
||||
else # Linux/other
|
||||
nvr --servername="${1}" +"${2}" "${3}"
|
||||
fi
|
||||
}
|
||||
|
||||
# read first line of /tmp/inverse-search-target.txt into the variable target
|
||||
read -r target < /tmp/inverse-search-target.txt
|
||||
|
||||
if [ ${target} = "TEX" ] # standard TEX inverse search
|
||||
then
|
||||
inverse_search "/tmp/texsocket" "${1}" "${2}" "${3}"
|
||||
elif [ ${target} = "LYTEX" ] # LilyPond LYTEX inverse search
|
||||
then
|
||||
|
||||
# change extension from ".tex" to ".lytex" using "${2%"tex"}lytex"
|
||||
# replace "lilybook-out/" with "" sed using 's/lilybook-out\///'
|
||||
lytex_file=$(echo "${2%"tex"}lytex" | sed 's/lilybook-out\///')
|
||||
|
||||
# get line in LYTEX file corresponding to line in TEX file
|
||||
lytex_to_tex_script="$HOME/.config/nvim/personal/lilypond-scripts/lytex-to-tex.sh"
|
||||
lytex_line=$(sh "${lytex_to_tex_script}" ${1} "${2}" "${lytex_file}")
|
||||
inverse_search "/tmp/lytexsocket" "${lytex_line}" "${lytex_file}" "${3}"
|
||||
|
||||
# echo "TEX line: ${1}"
|
||||
# echo "LYTEX line: ${lytex_line}"
|
||||
else
|
||||
exit
|
||||
fi
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
# Used for inverse search from a PDF in Zathura
|
||||
# to the corresponding *.tex in Neovim on Linux.
|
||||
# xdotool is used to return focus to the Vim window.
|
||||
#
|
||||
# SYNOPSIS
|
||||
# inverse <tex_file> <line_num> <window_id>
|
||||
# ARGUMENT
|
||||
# <tex_file>
|
||||
# Path to the LaTeX file to open in Neovim
|
||||
#
|
||||
# <line_num>
|
||||
# Line number to move the cursor to in the opened LaTeX file
|
||||
#
|
||||
# <window_id>
|
||||
# Numerical ID of the window in which Vim is running
|
||||
# as returned by `xdotool getactivewindow`.
|
||||
# E.g. 10485762
|
||||
nvr --remote-silent --servername=/tmp/texsocket +"${2}" "${1}"
|
||||
xdotool windowfocus ${3}
|
Loading…
Reference in New Issue