Ændrede diverse ting, især tilføjede jeg en masse lua-snippets
This commit is contained in:
parent
3e9363b016
commit
b1b7a050da
|
@ -1,8 +1,10 @@
|
|||
vim.opt.breakindentopt = "shift:2"
|
||||
vim.opt.shiftwidth = 4
|
||||
-- vim.opt.breakindentopt = "shift:2"
|
||||
-- Replacement for this: vim.opt.showbreak = "↪ "
|
||||
vim.opt.shiftwidth = 2
|
||||
vim.opt.softtabstop = 2
|
||||
vim.opt.tabstop = 2
|
||||
vim.opt.textwidth = 0
|
||||
|
||||
|
||||
vim.cmd([[
|
||||
function! MyFormatExpr(start, end)
|
||||
silent execute a:start.','.a:end.'s/[.!?]\zs /\r/g'
|
||||
|
|
|
@ -33,7 +33,7 @@ vim.opt.signcolumn = "yes"
|
|||
|
||||
vim.opt.updatetime = 250
|
||||
-- For which-key
|
||||
vim.opt.timeoutlen = 300
|
||||
vim.opt.timeoutlen = 500
|
||||
|
||||
vim.opt.list = true
|
||||
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" }
|
||||
|
|
|
@ -25,6 +25,10 @@ return {
|
|||
},
|
||||
config = function()
|
||||
require("luasnip.loaders.from_snipmate").lazy_load()
|
||||
require("luasnip.loaders.from_lua").lazy_load({
|
||||
-- If you set path manually, luasnip has to scan less
|
||||
-- paths = "~/.config/nvim/snippets/",
|
||||
})
|
||||
end,
|
||||
},
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
|
@ -36,7 +40,17 @@ return {
|
|||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
luasnip.config.setup({ enable_autosnippets = true })
|
||||
|
||||
vim.keymap.set(
|
||||
"n",
|
||||
"<Leader>L",
|
||||
"<Cmd>lua require('luasnip.loaders.from_lua').load({paths = '~/.config/nvim/luasnippets/'})<CR>"
|
||||
)
|
||||
luasnip.config.setup({
|
||||
enable_autosnippets = true,
|
||||
store_selection_keys = "<Tab>",
|
||||
update_events = "TextChanged,TextChangedI",
|
||||
})
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
|
@ -51,22 +65,60 @@ return {
|
|||
["<C-p>"] = cmp.mapping.select_prev_item(),
|
||||
["<C-u>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-b>"] = cmp.mapping.scroll_docs(-8),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(8),
|
||||
-- ["<C-b>"] = cmp.mapping.scroll_docs(-8),
|
||||
-- ["<C-f>"] = cmp.mapping.scroll_docs(8),
|
||||
-- Accept ([y]es) the completion
|
||||
["<C-y>"] = cmp.mapping.confirm({ select = true }),
|
||||
["<CR>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
if luasnip.expandable() then
|
||||
luasnip.expand()
|
||||
else
|
||||
cmp.confirm({ select = true })
|
||||
end
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end),
|
||||
-- Manually trigger a completion from nvim-cmp (normally not needed)
|
||||
["<C-Space>"] = cmp.mapping.complete({}),
|
||||
["<C-l>"] = cmp.mapping(function()
|
||||
if luasnip.expand_or_locally_jumpable() then
|
||||
if luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<C-j>"] = cmp.mapping(function()
|
||||
if luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
end
|
||||
end, { "n", "i", "s" }),
|
||||
["<C-k>"] = cmp.mapping(function()
|
||||
if luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
end
|
||||
end, { "n", "i", "s" }),
|
||||
["<C-h>"] = cmp.mapping(function()
|
||||
if luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
-- Better completions, especially for latex
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif luasnip.locally_jumpable(1) then
|
||||
luasnip.jump(1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
}),
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
return {
|
||||
"windwp/nvim-autopairs",
|
||||
event = "InsertEnter",
|
||||
opts = {}
|
||||
opts = {
|
||||
disable_filetype = { "tex" },
|
||||
},
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ return { -- Autoformat
|
|||
-- Conform can also run multiple formatters sequentially
|
||||
-- python = { "isort", "black" },
|
||||
python = { "autopep8", "black" },
|
||||
-- latex = { "latexindent" },
|
||||
-- tex = { "latexindent" },
|
||||
--
|
||||
-- You can use a sub-list to tell conform to run *until* a formatter is found.
|
||||
-- javascript = { { "prettierd", "prettier" } },
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
local M = {}
|
||||
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
|
||||
local in_mathzone = function()
|
||||
return vim.fn["vimtex#syntax#in_mathzone"]() == 1
|
||||
end
|
||||
|
||||
local in_text = function()
|
||||
return vim.fn["vimtex#syntax#in_mathzone"]() == 0
|
||||
end
|
||||
|
||||
M.in_mathzone = in_mathzone
|
||||
M.in_text = in_text
|
||||
|
||||
-- "as" for "Auto snippet"
|
||||
local function as(trigger, nodes, opts)
|
||||
opts = opts or {}
|
||||
-- Add snippetType = "autosnippet" to the first parameter
|
||||
if type(trigger) == "table" then
|
||||
trigger.snippetType = "autosnippet"
|
||||
else
|
||||
trigger = { trig = trigger, snippetType = "autosnippet" }
|
||||
end
|
||||
return s(trigger, nodes, opts)
|
||||
end
|
||||
|
||||
M.as = as
|
||||
|
||||
-- "asm" for "Auto snippet math"
|
||||
function M.asm(trigger, nodes, opts)
|
||||
-- Only trigger commands in mathzones
|
||||
opts = opts or {}
|
||||
opts.condition = in_mathzone
|
||||
return as(trigger, nodes, opts)
|
||||
end
|
||||
-- Add snippetType = "autosnippet" to the first parameter
|
||||
-- if type(trigger) == "table" then
|
||||
-- trigger.snippetType = "autosnippet"
|
||||
-- else
|
||||
-- trigger = { trig = trigger, snippetType = "autosnippet" }
|
||||
-- end
|
||||
-- return s(trigger, nodes, opts)
|
||||
-- end
|
||||
|
||||
-- "ast" for "Auto snippet text"
|
||||
function M.ast(trigger, nodes, opts)
|
||||
-- Only trigger commands in mathzones
|
||||
opts = opts or {}
|
||||
opts.condition = in_text
|
||||
return as(trigger, nodes, opts)
|
||||
-- -- Add snippetType = "autosnippet" to the first parameter
|
||||
-- if type(trigger) == "table" then
|
||||
-- trigger.snippetType = "autosnippet"
|
||||
-- else
|
||||
-- trigger = { trig = trigger, snippetType = "autosnippet" }
|
||||
-- end
|
||||
-- return s(trigger, nodes, opts)
|
||||
end
|
||||
--
|
||||
return M
|
|
@ -0,0 +1,14 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
-- local f = ls.function_node
|
||||
-- local d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
return {
|
||||
s({ trig = "lolol" }, { t("LuaSnip test") }),
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
-- local f = ls.function_node
|
||||
-- local d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
return {
|
||||
-- Snippet snippets
|
||||
s(
|
||||
{ trig = "asm", descr = "Autosnippet in math environment" },
|
||||
fmta(
|
||||
[[asm("<>", fmta("<>", { <> })),]],
|
||||
{ i(1, "trig"), i(2), i(3, "i(1)") }
|
||||
)
|
||||
),
|
||||
s(
|
||||
{ trig = "as", descr = "Autosnippet (own defined function)" },
|
||||
fmta(
|
||||
[[as("<>", fmta("<>", { <> })),]],
|
||||
{ i(1, "trig"), i(2), i(3, "i(1)") }
|
||||
)
|
||||
),
|
||||
s(
|
||||
{ trig = "ast", descr = "Autosnippet in text mode" },
|
||||
fmta(
|
||||
[[ast("<>", fmta("<>", { <> })),]],
|
||||
{ i(1, "trig"), i(2), i(3, "i(1)") }
|
||||
)
|
||||
),
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
-- local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
-- local f = ls.function_node
|
||||
-- local d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
|
||||
-- from nvim/lua/
|
||||
local helpers = require("luasnip-helpers")
|
||||
local as = helpers.as
|
||||
local ast = helpers.ast
|
||||
return {
|
||||
-- Fonts
|
||||
ast("ttt", fmta("\\texttt{<>}", { i(1) })),
|
||||
-- asm("rm", fmta("\\mathrm{<>}", { i(1) })),
|
||||
ast("tbf", fmta("\\textbf{<>}", { i(1) })),
|
||||
ast("tsf", fmta("\\textsf{<>}", { i(1) })),
|
||||
ast("tit", fmta("\\textit{<>}", { i(1) })),
|
||||
-- Idk, maybe emph can be used in mathmode?
|
||||
ast("emp", fmta("\\emph{<>}", { i(1) })),
|
||||
-- These two normally not needed, as you would define "\R = \mathbb{R}",
|
||||
-- and so on.
|
||||
-- as("bb", fmta("\\mathbb{<>}", { i(1) })),
|
||||
-- as("cal", fmta("\\mathcal{<>}", { i(1) })),
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
-- local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
-- local f = ls.function_node
|
||||
-- local d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
local rep = require("luasnip.extras").rep
|
||||
local line_begin = require("luasnip.extras.expand_conditions").line_begin
|
||||
--
|
||||
-- AutoSnippet function "as":
|
||||
local function as(trigger, nodes, opts)
|
||||
opts = opts or {}
|
||||
-- Add snippetType = "autosnippet" to the first parameter
|
||||
if type(trigger) == "table" then
|
||||
trigger.snippetType = "autosnippet"
|
||||
else
|
||||
trigger = { trig = trigger, snippetType = "autosnippet" }
|
||||
end
|
||||
return s(trigger, nodes, opts)
|
||||
end
|
||||
|
||||
return {
|
||||
as(
|
||||
"eq",
|
||||
fmta(
|
||||
[[
|
||||
\[
|
||||
<>
|
||||
\]
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"\\[",
|
||||
fmta(
|
||||
[[
|
||||
\[
|
||||
<>
|
||||
\]
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"beg",
|
||||
fmta(
|
||||
[[
|
||||
\begin{<>}
|
||||
<>
|
||||
\end{<>}
|
||||
]],
|
||||
{ i(1), i(2), rep(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"als",
|
||||
fmta(
|
||||
[[
|
||||
\begin{align*}
|
||||
<>
|
||||
\end{align*}
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
as(
|
||||
"ali",
|
||||
fmta(
|
||||
[[
|
||||
\begin{align}
|
||||
<>
|
||||
\end{align}
|
||||
]],
|
||||
{ i(1) }
|
||||
),
|
||||
{ condition = line_begin }
|
||||
),
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
-- local f = ls.function_node
|
||||
-- local d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
|
||||
-- from nvim/lua/
|
||||
local helpers = require("luasnip-helpers")
|
||||
-- Autosnippet, only for math environments
|
||||
local asm = helpers.asm
|
||||
return {
|
||||
-- Greek letters
|
||||
asm(";a", { t("\\alpha") }),
|
||||
asm(";b", { t("\\beta") }),
|
||||
asm(";g", { t("\\gamma") }),
|
||||
asm(";G", { t("\\Gamma") }),
|
||||
asm(";d", { t("\\delta") }),
|
||||
asm(";D", { t("\\Delta") }),
|
||||
-- Next two are swapped on purpose - always use varepsilon!
|
||||
asm(";e", { t("\\varepsilon") }),
|
||||
asm(";ve", { t("\\epsilon") }),
|
||||
asm(";z", { t("\\zeta") }),
|
||||
asm(";t", { t("\\theta") }),
|
||||
asm(";vt", { t("\\vartheta") }),
|
||||
asm(";T", { t("\\Theta") }),
|
||||
asm(";i", { t("\\iota") }),
|
||||
asm(";k", { t("\\kappa") }),
|
||||
asm(";l", { t("\\lambda") }),
|
||||
asm(";L", { t("\\Lambda") }),
|
||||
asm(";m", { t("\\mu") }),
|
||||
asm(";n", { t("\\nu") }),
|
||||
asm(";x", { t("\\xi") }),
|
||||
asm(";X", { t("\\Xi") }),
|
||||
asm(";pi", { t("\\pi") }),
|
||||
asm(";Pi", { t("\\Pi") }),
|
||||
asm(";r", { t("\\rho") }),
|
||||
asm(";vr", { t("\\varrho") }),
|
||||
asm(";s", { t("\\sigma") }),
|
||||
asm(";S", { t("\\Sigma") }),
|
||||
asm(";t", { t("\\tau") }),
|
||||
asm(";u", { t("\\upsilon") }),
|
||||
asm(";U", { t("\\Upsilon") }),
|
||||
asm(";ph", { t("\\phi") }),
|
||||
-- Could be ";vph", but two letters seems nicer
|
||||
asm(";vp", { t("\\varphi") }),
|
||||
asm(";Ph", { t("\\Phi") }),
|
||||
asm(";c", { t("\\chi") }),
|
||||
asm(";ps", { t("\\psi") }),
|
||||
asm(";Ps", { t("\\Psi") }),
|
||||
asm(";o", { t("\\omega") }),
|
||||
asm(";O", { t("\\Omega") }),
|
||||
|
||||
asm("ff", fmta("\\frac{<>}{<>}", { i(1), i(2) })),
|
||||
asm("tf", fmta("\\tfrac{<>}{<>}", { i(1), i(2) })),
|
||||
|
||||
asm({ trig = "__", wordTrig = false }, fmta("_{<>}", { i(1) })),
|
||||
asm({ trig = "^^", wordTrig = false }, fmta("^{<>}", { i(1) })),
|
||||
|
||||
-- Math fonts (in this document, so they only trigger in math environments)
|
||||
-- See https://tex.stackexchange.com/questions/58098/what-are-all-the-font-styles-i-can-use-in-math-mode
|
||||
asm("rm", fmta("\\mathrm{<>}", { i(1) })),
|
||||
asm("bf", fmta("\\boldsymbol{<>}", { i(1) })),
|
||||
asm("sf", fmta("\\mathsf{<>}", { i(1) })),
|
||||
asm("it", fmta("\\mathit{<>}", { i(1) })),
|
||||
asm("tt", fmta("\\mathtt{<>}", { i(1) })),
|
||||
-- These two normally not needed, as you would define "\R = \mathbb{R}",
|
||||
-- and so on.
|
||||
-- asm("bb", fmta("\\mathbb{<>}", { i(1) })),
|
||||
asm("cal", fmta("\\mathcal{<>}", { i(1) })),
|
||||
|
||||
-- Delimeters (in math). NEED CORRESPONDING DEFINITIONS IN PREAMBLE
|
||||
asm("pp", fmta("\\lr{<>}", { i(1) })),
|
||||
asm("ss", fmta("\\lrs{<>}", { i(1) })),
|
||||
asm("cc", fmta("\\lrc{<>}", { i(1) })),
|
||||
asm("sq", fmta("\\sqrt{<>}", { i(1) })),
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
-- Abbreviations used in this article and the LuaSnip docs
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
-- local f = ls.function_node
|
||||
-- local d = ls.dynamic_node
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local rep = require("luasnip.extras").rep
|
||||
-- local in_mathzone = function()
|
||||
-- return vim.fn["vimtex#syntax#in_mathzone"]() == 1
|
||||
-- end
|
||||
-- AutoSnippet function "as":
|
||||
local function as(trigger, nodes, opts)
|
||||
-- Only trigger commands in mathzones
|
||||
opts = opts or {}
|
||||
-- Add snippetType = "autosnippet" to the first parameter
|
||||
if type(trigger) == "table" then
|
||||
trigger.snippetType = "autosnippet"
|
||||
else
|
||||
trigger = { trig = trigger, snippetType = "autosnippet" }
|
||||
end
|
||||
return s(trigger, nodes, opts)
|
||||
end
|
||||
|
||||
return {
|
||||
as({ trig = "{{", wordTrig = false }, fmta("{<>}", { i(1) })),
|
||||
as({ trig = "[[", wordTrig = false }, fmta("[<>]", { i(1) })),
|
||||
as({ trig = "((", wordTrig = false }, fmta("(<>)", { i(1) })),
|
||||
as({ trig = "{}", wordTrig = false }, fmta("{<>}", { i(1) })),
|
||||
as({ trig = "[]", wordTrig = false }, fmta("[<>]", { i(1) })),
|
||||
as({ trig = "()", wordTrig = false }, fmta("(<>)", { i(1) })),
|
||||
as("mm", fmta("$<>$", { i(1) })),
|
||||
as("$$", fmta("$<>$", { i(1) })),
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
snippet dmo "\DeclareMathOperator"
|
||||
\\DeclareMathOperator{${1}}{${2}}
|
||||
#snippet dmo "\DeclareMathOperator"
|
||||
# \\DeclareMathOperator{${1}}{${2}}
|
||||
|
||||
snippet $$ "$Math$"
|
||||
\$${1:VISUAL}\$
|
||||
#snippet $$ "$Math$"
|
||||
# \$${1:VISUAL}\$
|
||||
|
||||
snippet em "\emph{...}"
|
||||
\emph{${1:VISUAL}}
|
||||
#snippet em "\emph{...}"
|
||||
# \emph{${1:VISUAL}}
|
||||
|
||||
snippet \ "\[ ... \]"
|
||||
\[
|
||||
${1}
|
||||
\]
|
||||
#snippet \ "\[ ... \]"
|
||||
# \[
|
||||
# ${1}
|
||||
# \]
|
||||
|
|
Loading…
Reference in New Issue