nvim: Extend snippet capability

Enabled snippet completion from the first letter (allowing single letter
snippet prefixes).
Extended the luasnip usage and added a telescope extension to show all
enabled snippets for the current buffer.
This commit is contained in:
Marty Oehme 2024-06-17 13:15:15 +02:00
parent a7aca62a15
commit 8dbfa2dd13
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
4 changed files with 206 additions and 5 deletions

View file

@ -77,6 +77,7 @@
"smartcolumn.nvim": { "branch": "main", "commit": "d01b99355c7fab13233f48d0f28dc097e68a03f7" }, "smartcolumn.nvim": { "branch": "main", "commit": "d01b99355c7fab13233f48d0f28dc097e68a03f7" },
"stickybuf.nvim": { "branch": "master", "commit": "2160fcd536d81f5fa43f7167dba6634e814e3154" }, "stickybuf.nvim": { "branch": "master", "commit": "2160fcd536d81f5fa43f7167dba6634e814e3154" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" },
"telescope-luasnip.nvim": { "branch": "master", "commit": "11668478677de360dea45cf2b090d34f21b8ae07" },
"telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
"trouble.nvim": { "branch": "main", "commit": "09380a8ed0694dbfbbcf59f9eaac499e259cb75c" }, "trouble.nvim": { "branch": "main", "commit": "09380a8ed0694dbfbbcf59f9eaac499e259cb75c" },
"twilight.nvim": { "branch": "main", "commit": "8bb7fa7b918baab1ca81b977102ddb54afa63512" }, "twilight.nvim": { "branch": "main", "commit": "8bb7fa7b918baab1ca81b977102ddb54afa63512" },

View file

@ -3,6 +3,7 @@ return {
{ {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
branch = "main", branch = "main",
version = false,
dependencies = { dependencies = {
"andersevenrud/cmp-tmux", "andersevenrud/cmp-tmux",
"cbarrete/completion-vcard", "cbarrete/completion-vcard",
@ -19,11 +20,30 @@ return {
"kdheepak/cmp-latex-symbols", "kdheepak/cmp-latex-symbols",
"lukas-reineke/cmp-rg", "lukas-reineke/cmp-rg",
"crispgm/cmp-beancount", "crispgm/cmp-beancount",
"ray-x/cmp-treesitter", { "ray-x/cmp-treesitter", dependencies = { "nvim-treesitter/nvim-treesitter" } },
{
"saadparwaiz1/cmp_luasnip", "saadparwaiz1/cmp_luasnip",
dependencies = {
{ {
"L3MON4D3/LuaSnip", "L3MON4D3/LuaSnip",
dependencies = { "rafamadriz/friendly-snippets" }, dependencies = {
"rafamadriz/friendly-snippets",
{
"benfowler/telescope-luasnip.nvim",
dependencies = { { "nvim-telescope/telescope.nvim", optional = true } },
config = function()
require("telescope").load_extension("luasnip")
end,
},
},
build = "make install_jsregexp",
config = function()
require("luasnip.loaders.from_vscode").lazy_load({ exclude = { "markdown", "quarto" } })
require("luasnip.loaders.from_snipmate").lazy_load()
end,
},
},
}, },
}, },
config = function() config = function()
@ -83,7 +103,7 @@ return {
{ name = "otter" }, { name = "otter" },
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "nvim_lsp_signature_help" }, { name = "nvim_lsp_signature_help" },
{ name = "luasnip", keyword_length = 2 }, { name = "luasnip", keyword_length = 1 },
{ name = "pandoc_references" }, { name = "pandoc_references" },
{ name = "calc" }, { name = "calc" },
{ name = "path" }, { name = "path" },

View file

@ -0,0 +1,80 @@
# Markdown snippets
# Combination of snips from friendly-snippets and vim-snippets repos
snippet h1 Heading level 1
# ${0}
snippet h2 Heading level 2
## ${0}
snippet h3 Heading level 3
### ${0}
snippet h4 Heading level 4
#### ${0}
snippet h5 Heading level 5
##### ${0}
snippet h6 Heading level 6
##### ${0}
snippet ] Link
[${1:text}](${2:link})
snippet ]h Weblink
[${1:text}](https://${2:address})
snippet ]c Link filled with clipboard contents
[${1:text}](${2:`@+`})
snippet ]: Link reference style
[${1:id}]: ${2:text}
snippet ]] Footnote
[^${1:id}]${0}
[^${1:id}]: ${2:text}
snippet img Image link
![${1:alt}](${2:link})
snippet imgc Image link with clipboard content
![${1:alt}](${2:`@+`})
snippet ** Bold
**$0**
snippet __ Bold
__$0__
snippet --- Frontmatter
---
$0
---
# codeblocks
snippet `` Codeblock with language
\`\`\`${1:language}
${2:code}
\`\`\`
# table
snippet tb Simple table
| ${5:factors} | ${1:a} | ${2:b} |
| ------------- |------------- | ------- |
| ${3:f1} | ${0} | N |
| ${4:f2} | N | N |
# tasklists
snippet tl Tasklist item
- [ ] ${0:item}
snippet tl3 Tasklist item
- [ ] ${1:item}
- [ ] ${2:item}
- [ ] ${0:item}
# super/subscript - pandoc/extended markdown only
snippet sub Subscript
~${0}~
snippet sup Superscript
^${0}^

View file

@ -0,0 +1,100 @@
# Quarto extensions to markdown
extends markdown
# definitions list
snippet : Definition list
$1
: $0
snippet `` Codecell with language
\`\`\`{${1:language}}
${2:code}
\`\`\`
snippet ``p Codecell with language
\`\`\`{python}
${2:code}
\`\`\`
snippet ``r Codecell with language
\`\`\`{r}
${2:code}
\`\`\`
snippet pyfig2 Sub-Figures from python codecell
\`\`\`{python}
#| label: fig-${1:label}
#| fig-cap: "${2:caption}"
#| fig-subcap:
#| - "${3:subcap1}"
#| - "${3:subcap2}"
#| layout-ncol: 2
${0:code}
\`\`\`
snippet pyfig Figure from python codecell
\`\`\`{python}
#| label: fig-${1:label}
#| fig-cap: "${2:caption}"
${0:code}
\`\`\`
snippet fig General figure
![${1:caption}](${3:figure}){#fig-${2:label}}
snippet pytab Figure from python codecell
\`\`\`{python}
#| label: tbl-${1:label}
#| tbl-cap: "${2:caption}"
${0:code}
\`\`\`
snippet fref Figure crossref
@fig-${1:label}
snippet tref Table crossref
@tbl-${1:label}
snippet sref Section crossref
@sec-${1:label}
snippet eref Equation crossref
@eq-${1:label}
snippet cite Citation
[@${1:bib-key}]
snippet fn Footnote
[^${1:id}]
[^${1}]: ${2:text}
snippet shortcode Shortcode
{{< $0 >}}
snippet div Div block
::: {.${1:class}}
$0
:::
snippet note Callout note
::: {.callout-note}
$0
:::
snippet warn Callout warning
::: {.callout-warning}
$0
:::
snippet import Callout important
::: {.callout-important}
$0
:::
snippet tip Callout tip
::: {.callout-tip}
$0
:::
snippet caut Callout caution
::: {.callout-caution}
$0
:::