diff --git a/init.lua b/init.lua index 9ef14e6..69aa5f3 100644 --- a/init.lua +++ b/init.lua @@ -105,6 +105,9 @@ require('lazy').setup({ -- Adds LSP completion capabilities 'hrsh7th/cmp-nvim-lsp', + + -- Adds completion capabilities for text in buffers + 'hrsh7th/cmp-buffer', -- Adds path completion capabilities 'hrsh7th/cmp-path', @@ -531,7 +534,7 @@ mason_lspconfig.setup_handlers { end, } --- [[ Configure nvim-cmp ]] +-- [[ Configure nvim-cmp, and LuaSnip ]] -- See `:help cmp` local cmp = require 'cmp' local luasnip = require 'luasnip' @@ -548,6 +551,10 @@ luasnip.config.setup { -- Load snippets from ~/.config/nvim/LuaSnip/ require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"}) +-- Keymap to reload snippets +-- https://www.ejmastnak.com/tutorials/vim-latex/luasnip/#refreshing-snippets-from-a-separate-vim-instance +vim.keymap.set('n', 'L', 'lua require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"})', { desc = 'Reload [L]uaSnippets' }) + cmp.setup { snippet = { expand = function(args) @@ -585,6 +592,13 @@ cmp.setup { }, sources = { { name = 'nvim_lsp' }, + { + name = 'buffer', + option = { + keyword_length = 4, + keyword_pattern = [[\k\+]], + }, + }, { name = 'luasnip' }, { name = 'path' }, }, diff --git a/my_snippets/markdown.lua b/my_snippets/markdown.lua index 75bfa6c..052cf26 100644 --- a/my_snippets/markdown.lua +++ b/my_snippets/markdown.lua @@ -86,12 +86,12 @@ return { }, fmt( [[ - --- - title: {1} - date: {3} - id: {4} - tags: [{2}] - --- + --- + title: {1} + date: {3} + id: {4} + tags: [{2}] + --- ]], { @@ -147,5 +147,20 @@ return { }, { repeat_duplicates = true } ) + ), + s( + { + trig = "tags", + name = "Tags", + dscr = "Insert a one-line tags array, in a text file (markdown)." + }, + fmt( + [[ + tags: [{}] + ]], + { + i(1, "tags") + } + ) ) }