From 983dfae04ce2b62ecacda1d74f1cf17468765ff2 Mon Sep 17 00:00:00 2001 From: iGor milhit Date: Thu, 22 Jun 2023 15:30:23 +0200 Subject: [PATCH] completion: add completion for text in the buffer - Adds completion capabilities for text (in the current buffer), with the help of `cmp-buffer`). - Set the keyword_length to 4 in order to lighten the buffer completion. - Supports non ASCII chars in text completion (cmp-buffer). - Restore the luasnip configuration inside the nvim-cmp configuration, as it is indeed closely related. I didn't understood it in the first place. - Add a markdown snippet to add a tags line in my incremental notes (journal). - Expand the French dictionnary. Co-Authored-by: iGor milhit --- init.lua | 16 +++++++++++++++- my_snippets/markdown.lua | 27 +++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) 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") + } + ) ) }